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

匿名 (未验证) 提交于 2019-12-03 01:29:01

问题:

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.

  1. I created a new database "NewEfDatabase".

  2. Then changed my "ApplicationServices" connectionString in Web.config to point to my new database with integrated security.

But then I get this error:

"CREATE DATABASE permission denied in database 'master'."

So...

a) What permissions does EF 4.1 CF need on said SQL server to do its work?

b) Can I setup an empty database on SQL 2008 for EF 4.1 CF, or do I have to let it do all that work for me? (I'm not sure my DBA would appreciate letting my EF app have rights to do anything outside a particular database)

回答1:

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

Database.SetInitializer(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).



回答2:

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)



回答3:

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.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!