1

How can I access multiple databases in a single project for inserting data at the same time? Is it possible to use different connection strings in a single web.config file?

3
  • just put new connection string with different name and map with your new DB Commented Aug 11, 2015 at 8:17
  • 1
    Yes, it is possible You can use your custom implementation to connect to SQL Server and control which connection string to use. Commented Aug 11, 2015 at 8:18
  • for Debug and Release? Commented Aug 11, 2015 at 8:27

2 Answers 2

1

Yes it is possible.Use connectionStrings section in web.config

<connectionStrings>
  <add name="connection1" connectionString="Your Connection string" providerName="Your provider name"/>
  <add name="connection2" connectionString="Your Connection string" providerName="Your provider name"/>
  <add name="connection3" connectionString="Your Connection string" providerName="Your provider name"/>
 </connectionStrings>

use this connection string in your project as

ConfigurationManager.ConnectionStrings["Your connection string name"].ToString()
Sign up to request clarification or add additional context in comments.

Comments

1

Yes you can,

By adding many connection strings in your web.config file

As:

<connectionStrings>
  <add name="connection1" connectionString="First Connection string" providerName="Your provider name"/>
  <add name="connection2" connectionString="Second Connection string" providerName="Your provider name"/>
 </connectionStrings>

and in your code, you can call wich connection String you want as:

ConfigurationManager.ConnectionStrings["First Connection string"].ToString()

or

ConfigurationManager.ConnectionStrings["Second Connection string"].ToString()

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.