简体   繁体   English

数据库实体框架的名称已更改

[英]Changed name of database entity-framework

An error occurred while executing the command definition. 执行命令定义时发生错误。 See the inner exception for details. 有关详细信息,请参见内部异常。

I changed name of database. 我更改了数据库名称。 First when I have got PoliNameDatabase everything working correct but when I changed name of database in web.config PoliNameDatabaseTwo database does not work correct. 首先,当我获得PoliNameDatabase时,一切正常,但是当我在web.config中更改数据库名称时,PoliNameDatabaseTwo数据库无法正常工作。 I can see wrong connection to database even I change name in web.config (example: PoliNameDatabase.dbo.MyProcedure) where I have to also change this name of database in entity-framework? 即使更改web.config中的名称(例如PoliNameDatabase.dbo.MyProcedure),我也必须看到与数据库的错误连接,在这里我还必须在实体框架中更改此数据库的名称?

在此处输入图片说明

When you create a new ObjectContext or DbContext , there will be a default name for the connection string. 创建新的ObjectContextDbContext ,将为连接字符串提供默认名称。 The connection string should be the only thing you should alter to get the right database. 连接字符串应该是您更改以获得正确数据库的唯一选择。 What usually happen is that, for instance, if you have an assembly for Model and another for your application, you would have to change this connection string twice: In the model assembly, so that it would set the default name right and work properly in the designer, and in your web.config or app.config so the application will get in in runtime. 通常会发生这种情况,例如,如果您有一个Model的程序集和一个应用程序的程序集,则必须两次更改此连接字符串:在模型程序集中,这样它将正确设置默认名称并在其中正常工作设计器,并在您的web.configapp.config以便应用程序可以在运行时进入。

When you have the ObjectContext object, you can inspect the connection string from the property [your_object_context].ConnectionString . 当拥有ObjectContext对象时,可以从属性[your_object_context].ConnectionString检查连接字符串。 From DbContext , you would get it from [your_db_context].Database.Connection.ConnectionString . DbContext ,您将从[your_db_context].Database.Connection.ConnectionString获取它。

After you have the connection string name. 获得连接字符串名称之后。 Inspect ConfigurationManager.ConnectionStrings for checking it out. 检查ConfigurationManager.ConnectionStrings以将其检出。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM