EF 4.1 CF:CREATE DATABASE权限被拒绝在数据库'master'

编程入门 行业动态 更新时间:2024-10-19 14:38:48
本文介绍了EF 4.1 CF:CREATE DATABASE权限被拒绝在数据库'master'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

实体框架4.1代码首先在 localhost 上使用 SQLEXPRESS 但是,我现在可以连接到常规的 SQL 2008服务器。

  • 我创建了一个新数据库NewEfDatabase。

  • p>然后在 Web.config 指向我的新数据库具有集成的安全性。

  • 但是我收到这个错误:

    所以...

    a)EF 4.1 CF在所述SQL服务器上需要哪些权限才能完成工作?

    b)我可以设置一个空数据库对于EF 4.1 CF, SQL 2008 ,还是要让它为我所有的一切工作? (我不确定我的DBA是否会让我的EF应用程序有权在特定数据库之外执行任何操作)

    解决方案

    您确保将您的数据库初始化程序设置为您的代码中的 null :

    Database.SetInitializer< MyDbContext>(空);

    如果初始化程序可能尝试删除或创建新数据库,所有内置实现。您收到的错误表明,EF尝试删除/创建数据库,但没有在SQL Server实例中执行此操作。上面的一行是唯一可以避免这种情况的一般方法,适合现实环境(我认为甚至绝对必要),无论你不想意外删除(由于模型的改变或某些东西)。

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

    解决方案

    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).

    更多推荐

    EF 4.1 CF:CREATE DATABASE权限被拒绝在数据库'master'

    本文发布于:2023-10-15 03:05:29,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1493058.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:被拒   权限   数据库   CF   EF

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!