-3

I have the next connectionstring file:

<?xml version="1.0"?>
<connectionStrings>
  <add name="DefaultConnection"
    connectionString="Application Name=CalculatorTest;Server=PC01;Initial catalog=MyDB;Integrated Security=true" />
</connectionStrings>

I want to add a new connection, for example "MyDBTest", staying:

<?xml version="1.0"?>
<connectionStrings>
  <add name="DefaultConnection"
    connectionString="Application Name=CalculatorTest;Server=PC01;Initial catalog=MyDB;Integrated Security=true" />

  <add name="NewDefaultConnection"
    connectionString="Application Name=CalculatorTest;Server=PC01;Initial catalog=MyDBTest;Integrated Security=true" />
</connectionStrings>

How do I do it from C# Mvc 5?

2

1 Answer 1

0

Right click on your project and add an Entity Data Object, then enter the name you want it to be called; chose code first from database, then enter the server address and you can also select which tables from the db you want. This will create the connection string for you. I would however recommend doing this in a separate class library so it’s easier to maintain. Note: if you do use it in a separate class library, you will need to look in the Web.config and copy it over to your main application web.config. Also you will want to add the reference of it in your project references.

Sign up to request clarification or add additional context in comments.

3 Comments

Yes yes, but I currently have the connectionstring file with one connection. I need to add new connections on the same file.
Do you know the other connection string?
Yes, I know all of data. I don't know how to add to the file in runtime.

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.