私はすでに同様の例を見ましたが、私の問題の解決策はありませんでした。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