问题描述
我有一个小的asp.net mvc4应用程序(在我的本地机器工作正常),它使用实体框架v4.1.0.0与ADO.net DbContext生成器(SQL Server 2008 r2)
I have a small asp.net mvc4 application (working fine in my local machine), that uses entity framework v4.1.0.0 with ADO.net DbContext Generator.(SQL Server 2008 r2)
我在Visual Studio 2010中通过添加可部署的依赖关系...上下文菜单添加了更新的dll版本。
I am adding newer versions of dlls required through the "Add Deployable Dependencies..." context menu in Visual Studio 2010.
我有一个共享的主机与godaddy.com,我已经将文件上传到服务器并创建了数据库,现在来了问题。当我尝试浏览我的网站时,我得到以下错误:
I have a shared hosting with godaddy.com, I have uploaded the files to server and created the database, now here comes the problem.When I try to browse my site I get the following error:
数据库'master'中的CREATE DATABASE权限被拒绝。
我看了一下,发现这个错误是由EF代码首先尝试创建数据库。但是我不希望EF代码首先重新创建数据库,我如何关闭这个自动数据库创建?我没有意图使用代码优先功能无论如何,
I looked this up around and found out that this error was caused by EF code first trying to create database.but i do not want EF code first to recreate the database, how do i turn off this automatic database creation altogether? I have no intentions of using the code-first feature whatsoever.
请帮助。
推荐答案
将此代码放入Global.asax的Application_Start()方法或DbContext类的构造函数
put this code into the Application_Start() method of Global.asax or constructor on your DbContext class
Database.SetInitializer<MyContext>(null);
如果要在更改POCO域时重新创建数据库,请使用以下代码,而不是以上代码
If you want to recreate database when POCO domains are changed, use following code instead of above
Database.SetInitializer<MyContext>(new DropCreateDatabaseIfModelChanges<MyContext>());
这篇关于实体框架正在尝试创建一个数据库,但它不是我想要的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!