简体   繁体   English

更改实体框架中的连接字符串(模型优先)

[英]Change connection string in Entity Framework(Model First)

I am using entity framework model first approach in WCF . 我在WCF使用实体框架模型第一种方法。 The EF creates a connection stringwhich looks something like this: EF创建一个连接字符串,如下所示:

automatically for the first time. 第一次自动。

Now I want to change the connection string as database is located in other server. 现在我想更改连接字符串,因为数据库位于其他服务器中。

How can I do it? 我该怎么做?

Connection string looks like this for now: 连接字符串现在看起来像这样:

<connectionStrings><add name="Entities" connectionString="metadata=res://*/Database.Model1.csdl|res://*/Database.Model1.ssdl|res://*/Database.Model1.msl;provider=Oracle.ManagedDataAccess.Client;provider connection string=&quot;data source=AB;password=admin;persist security info=True;user id=TEST&quot;" providerName="System.Data.EntityClient" /></connectionStrings>)

Regards Anudeep 关心Anudeep

一种简单的方法是使用新的连接详细信息修改app.config或web.config文件,因此调用var context = new DataContext(“ NewServerEntities ”)构造函数将在配置文件中使用命名连接。

<add name="NewServerEntities" connectionString="metadata=res://*/Database.Model1.csdl|res://*/Database.Model1.ssdl|res://*/Database.Model1.msl;provider=Oracle.ManagedDataAccess.Client;provider connection string=&quot;data source=NewServer;password=admin;persist security info=True;user id=TEST&quot;" providerName="System.Data.EntityClient" />

Remove the connection string from the app.config file, re-run the entity Data Model wizard by right-clicking the designer and chose Update Model From Database, it will guide you to build a new connection. 从app.config文件中删除连接字符串,通过右键单击设计器并选择Update Model From Database重新运行实体数据模型向导,它将指导您构建新连接。 Or else directly edit the Datasource and credentials in the existing connection string in App.config. 或者直接编辑App.config中现有连接字符串中的数据源和凭据。

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

相关问题 Code First Entity Framework - 更改连接字符串 - Code First Entity Framework - change connection string 实体框架模型的第一个连接字符串在将代码移至服务器时如何更改 - Entity framework model first connection string how to change while moving code to server 数据库优先和实体框架动态连接字符串 - Database first and Entity Framework Dynamic Connection String 实体框架数据模型和连接字符串 - entity framework data model and connection string 实体框架:在运行时更改连接字符串 - Entity Framework : Change connection string at runtime 以编程方式创建连接字符串以将Entity Framework Code-First模型与现有Sql Azure联合数据库进行映射 - Programmatically creating a connection string for mapping an Entity Framework Code-First model with an existing Sql Azure federation database 如何在实体框架数据库第一个模型连接字符串中动态包含工作站ID? - How to include work station id in entity framework database first model connection string dynamically? 实体框架连接字符串 - Entity framework connection string 实体框架没有连接字符串,但它有吗? - Entity Framework no connection string but it is there? 将 Entity Framework Code First 与动态连接字符串一起使用 - Using Entity Framework Code First with a dynamic connection string
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM