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??

tereško
  • 58,060
  • 25
  • 98
  • 150
Lücks
  • 3,806
  • 2
  • 40
  • 54
  • Take a look on [CREATE DATABASE permission denied](http://stackoverflow.com/questions/11231934/create-database-permission-denied-in-database-master-ef-code-first) question – Sergey Berezovskiy Aug 15 '13 at 20:59

1 Answers1

3

In your EF initialization code, make sure you specify the connection string name like this

public class MyDbContext : DbContext
{
    public MyDbContext() : base("MyContext") {}
}
zs2020
  • 53,766
  • 29
  • 154
  • 219