有关将连接字符串传递给DbContext的错误(string nameOrConnectionString)

时间:2018-03-15 08:43:15

标签: c# entity-framework

我试图将data source=(local);initial catalog=xxx;integrated security=false;user id=sa;password=yyy;传递给我的EFDbContext。我所做的是

public class EFDbContext : DbContext
{
    public EFDbContext() : base(@"data source=(local);initial catalog=xxx;integrated security=false;userid=sa;password=yyy;MultipleActiveResultSets=True;App=EntityFramework")
    {
    }
}

但它引起了一个错误说

  

“不支持关键字:'初始目录'”

当我运行程序时。这是我的连接字符串格式的问题吗?

1 个答案:

答案 0 :(得分:0)

public class EFDbContext : DbContext
{
    public EFDbContext() : base(@"data source=(local);initial catalog=xxx;integrated security=false;userid=sa;password=yyy;MultipleActiveResultSets=True;App=EntityFramework")
    {
        this.Database.Connection.Provider = "System.Data.SqlClient";
    }
}