EF 4.1 CF:数据库“master”中的 CREATE DATABASE 权限被拒绝
Entity Framework 4.1 Code First 与 localhost
上的 SQLEXPRESS
配合得很好。不过,我现在已准备好连接到常规 SQL 2008 服务器
。
我创建了一个新数据库“NewEfDatabase”。
然后更改了
Web.config
中的“ApplicationServices
”connectionString
,以指向具有集成安全性的新数据库。
但随后我收到此错误:
“CREATE DATABASE 权限在数据库 'master' 中被拒绝。
”
所以...
a) EF 4.1 CF 在所述 SQL 服务器上需要什么权限才能完成其工作?
b) 我可以在 SQL 2008
上为 EF 4.1 CF 设置一个空数据库,还是必须让它为我完成所有工作? (我不确定我的 DBA 是否愿意让我的 EF 应用程序有权执行特定数据库之外的任何操作)
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
.
I created a new database "NewEfDatabase".
Then changed my "
ApplicationServices
"connectionString
inWeb.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)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您是否确保在代码中将数据库初始值设定项设置为
null
:所有内置实现(如果初始值设定项可能会尝试删除或创建新数据库)。您收到的错误表明 EF 尝试删除/创建数据库,但无权在您的 SQL Server 实例中执行此操作。上面的行是通常避免这种情况的唯一选择,并且适合(我认为甚至绝对必要)无论如何您不希望意外删除(由于模型更改或其他原因)的实时环境。
Did you make sure to set your Database Initializer to
null
in your code: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).
在 SQL Server 中为您的应用程序设置登录名。授予该用户 dbcreator 权限(通过右键单击登录名,转到服务器角色,然后选中“dbcreator”复选框)
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)
尽量不要使用 Windows 集成授权,就像我在这篇文章中回复的那样: EF 代码优先 - {“在数据库“master”中拒绝创建数据库权限。”}。
这对我有用。
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.