-1

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

2 Answers 2

2

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" />
Sign up to request clarification or add additional context in comments.

Comments

2

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.