0

I started an application using Entity Framework Code First. In my Web.config I added the connection string:

<add name="MyContext" connectionString="Data Source=server\mssqlserver2008;Initial Catalog=dbname;persist security info=True; Integrated Security=SSPI" providerName="System.Data.SqlClient" />

And I received a error when I tried to access my Controller: CREATE DATABASE permission denied in database 'master'

So, I debugged the code and I found that the attribute "ConnectionString" inside my Context it's different from my Web.config:

Data Source=.\\SQLEXPRESS;Initial Catalog=MyProject.Models.MyContext;Integrated Security=True;MultipleActiveResultSets=True;Application Name=EntityFrameworkMUE

Why the ConnectionString is wrong??

4

1 回答 1

3

在您的 EF 初始化代码中,确保您像这样指定连接字符串名称

public class MyDbContext : DbContext
{
    public MyDbContext() : base("MyContext") {}
}
于 2013-08-15T20:54:22.140 回答