EF 4.1 CF: CREATE DATABASE permission denied in database 'master'

后端 未结 3 1203
醉话见心
醉话见心 2020-12-16 03:13

Entity Framework 4.1 Code First works great with SQLEXPRESS on localhost. However, I\'m now ready to connect to a regular SQL 2008 server

相关标签:
3条回答
  • 2020-12-16 03:26

    Did you make sure to set your Database Initializer to null in your code:

    Database.SetInitializer<MyDbContext>(null);
    

    All built-in implementations if the initializer may try to drop or create a new database. The error you get indicate that EF tried to drop/create a database but hasn't the right to do so in your SQL Server instance. The line above is the only option to avoid this generally and is suited (I think even absolutely necessary) for live environments anyway where you don't want accidental deletion (due to model changes or something).

    0 讨论(0)
  • 2020-12-16 03:28

    Try not to used the windows-intergrated authorization, like what I replied in this post: EF Code First - {"CREATE DATABASE permission denied in database 'master'."}. It worked for me.

    0 讨论(0)
  • 2020-12-16 03:38

    Setup a login for your application within SQL server. Give that user dbcreator permission (by right clicking on the login, go to server roles, and check the "dbcreator" checkbox)

    0 讨论(0)
提交回复
热议问题