sangeetha k

sangeetha k

  • NA
  • 207
  • 49.3k

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

Dec 20 2017 1:40 AM
Help me where I am wrong
 
Here with I attach my mvc code.
 
#view
  1. @model Mvcpractice1.Models.Employee  
  2. @{  
  3. ViewBag.Title = "Employee Details";  
  4. }  
  5. <h2>Employee Details</h2>  
  6. <table>  
  7. <tr>  
  8. <td>  
  9. <b>Employee Id:</b>  
  10. </td>  
  11. <td>  
  12. @Model.EmployeeId  
  13. </td>  
  14. </tr>  
  15. <tr>  
  16. <td><b>Employee Phoneno:</b></td>  
  17. <td>@Model.Phoneno</td>  
  18. </tr>  
  19. <tr>  
  20. <td><b>Employee Name:</b></td>  
  21. <td>@Model.Name</td>  
  22. </tr>  
  23. </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 Mvcpractice1.Models;  
  7. namespace Mvcpractice1.Controllers  
  8. {  
  9. public class EmployeeController : Controller  
  10. {  
  11. //  
  12. // GET: /Employee/  
  13. public ActionResult Index( int id)  
  14. {  
  15. EmployeeContext emp=new EmployeeContext();  
  16. Employee emp1= emp.Employees.Single(x=>x.EmployeeId == id);  
  17. return View(emp1);  
  18. }  
  19. }  
  20. }  
#DbContetxt
  1. namespace Mvcpractice1.Models  
  2. {  
  3. public class EmployeeContext:DbContext  
  4. {  
  5. public DbSet<Employee> Employees { getset; }  
  6. }  
  7. }  
#webConfig
  1. <connectionStrings>  
  2. <add name="EmployeeContext" connectionString="Data Source=CHV8LTDBNC01\LENTRACSDB2008;Integrated Security=True ;Database=AdventureWorks2008" providerName="System.Data.SqlClient" />  
  3. </connectionStrings>  
But this is yeilding
 
An exception of type 'System.Data.Entity.Core.EntityException' occurred in EntityFramework.SqlServer.dll but was not handled in user code
Additional information: The underlying provider failed on Open.

Answers (3)