비슷한 예제를 보았지만 그 중 아무 것도 내 문제를 해결하지 못했습니다.Entity Framework를 사용하여 연결을 설정할 수 없습니다.
데이터를 가져 오기 위해 데이터베이스에 연결하려고합니다. 페이지를로드 할 때
나는 오류 얻을 : 나는 여기에 몇 가지 예제를 통해 찾아 볼 "The underlying provider failed on Open."
을하지만, 해결책을 찾을 수 없습니다.
나는에서 연결을 만든 내 Web.config
: <add name="EmployeeContext" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=Sample; integrated security=true" providerName="System.Data.SqlClient"/>
내가 컨텍스트 파일이 :
[Table("tblEmployee")]
public class EmployeeContext : DbContext
{
public DbSet<Employee> Employee { get; set; }
}
나는 연결하고 컨트롤러에서 데이터를 얻으려고 :
public ActionResult Details(int id)
{
EmployeeContext employeeContext = new EmployeeContext();
Employee employee = employeeContext.Employee.Single(emp => emp.EmployeeId == id);
return View(employee);
}
그러나 데이터를 가져올 때 페이지를로드 할 때 오류가 발생합니다. "The underlying provider failed on Open."
내가 뭘 잘못하고 있니?
프로젝트 파일을 사용 중입니다. – gene
데이터 소스 = (LocalDb) \ v11.0을 데이터 소스 =로 변경하십시오. – bfly
방금 했어 : 데이터 원본 = Server_Name \ SQLEXPRESS – gene