Ashish Agrawal
Ashish Agrawal

Reputation: 45

Change connection string in Entity Framework(Model First)

I am using entity framework model first approach in WCF. The EF creates a connection stringwhich looks something like this:

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

Upvotes: -1

Views: 1787

Answers (2)

Naveen
Naveen

Reputation: 1502

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. Or else directly edit the Datasource and credentials in the existing connection string in App.config.

Upvotes: 2

reckface
reckface

Reputation: 5858

One simple way is to modify the app.config or web.config file with the new connection details so calling the var context = new DataContext("NewServerEntities") constructor will use the named connection in your config file.

<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" />

Upvotes: 2

Related Questions