[英]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="data source=AB;password=admin;persist security info=True;user id=TEST"" 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="data source=NewServer;password=admin;persist security info=True;user id=TEST"" 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.