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?
-
just put new connection string with different name and map with your new DBwiretext– wiretext2015-08-11 08:17:54 +00:00Commented Aug 11, 2015 at 8:17
-
1Yes, it is possible You can use your custom implementation to connect to SQL Server and control which connection string to use.Nikhil Chavan– Nikhil Chavan2015-08-11 08:18:45 +00:00Commented Aug 11, 2015 at 8:18
-
for Debug and Release?Backs– Backs2015-08-11 08:27:58 +00:00Commented Aug 11, 2015 at 8:27
Add a comment
|
2 Answers
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()
Comments
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()