mevada kamlesh

mevada kamlesh

  • NA
  • 66
  • 29.4k

Asp.net MVC: the underlying provider failed to open. error

Mar 27 2018 5:43 AM
Help me where I am wrong
 
Here with I attach my mvc code.
 
#view
  1. @model MVCDemo2.Models.Employee  
  2. @{  
  3. ViewBag.Title = "Employee Details";  
  4. }  
  5. <h2>Employee Details</h2>  
  6. <table style="font-family:Arial">  
  7. <tr>  
  8. <td>  
  9. <b>Employee Id:</b>  
  10. </td>  
  11. <td>  
  12. @Model.EmployeeId  
  13. </td>  
  14. </tr>  
  15. <tr>  
  16. <td>  
  17. <b>Name:</b>  
  18. </td>  
  19. <td>  
  20. @Model.Name  
  21. </td>  
  22. </tr>  
  23. <tr>  
  24. <td>  
  25. <b>Gender:</b>  
  26. </td>  
  27. <td>  
  28. @Model.Gender  
  29. </td>  
  30. </tr>  
  31. <tr>  
  32. <td>  
  33. <b>City:</b>  
  34. </td>  
  35. <td>  
  36. @Model.City  
  37. </td>  
  38. </tr>  
  39. </table>  
#controller
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Web;  
  5. using System.Web.Mvc;  
  6. using MVCDemo2.Models;  
  7. namespace MVCDemo2.Controllers  
  8. {  
  9. public class EmployeeController : Controller  
  10. {  
  11. public ActionResult Details(int id)  
  12. {  
  13. EmployeeContext employeeContext = new EmployeeContext();  
  14. Employee employee = employeeContext.Employees.Single(emp => emp.EmployeeId == id);  
  15. return View(employee);  
  16. }  
  17. }  
  18. }  
#EmployeeContext
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Web;  
  5. using System.Data.Entity;  
  6.   
  7. namespace MVCDemo2.Models  
  8. {  
  9. public class EmployeeContext : DbContext  
  10. {  
  11. public DbSet<Employee> Employees { getset; }  
  12. }  
  13. }  
#webConfig
  1. <connectionStrings>  
  2. <add name="EmployeeContext" connectionString="Data Source=ADMIN-PC3\SQLEXPRESS;Initial Catalog=employee;Integrated Security=true"  
  3. providerName="System.Data.SqlClient"/>  
  4. </connectionStrings>  
but Run time Error "EntityException was unhandled by user code" The Underlying provider failed on on Open.

Answers (4)