Click here to Skip to main content
15,898,538 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
HTML
<add name="HelpdeskConString" connectionString="Data Source=.;Initial Catalog=CasDB;Integrated Security=True"/>


HTML
<add name="HelpdeskConString" connectionString="Data Source=.;Initial Catalog=HelpDB;Integrated Security=True"/>



I have two database in my web projct its containg two sub project we wanted two use both database in web config..

how to set condition in this situation..?
Posted
Updated 20-May-14 20:33pm
v2

You can not have two different database connection strings with the same name (key) in the web config.

However, you can have two different classes with the same property and different connection strings. In this way, based on your condition, you can call appropriate class and respective database.

You need to give an example of your scenario so that people can suggest different ideas.

Hope this helps.
 
Share this answer
 
Comments
Maciej Los 21-May-14 3:09am    
+5!
Name should be Different


C#
<add name="ConString1" connectionstring="Data Source=.;Initial Catalog=CasDB;Integrated Security=True" />


C#
<add name="Constring2" connectionstring="Data Source=.;Initial Catalog=HelpDB;Integrated Security=True" />
 
Share this answer
 
You can use multiple connection string like that just give name at codebehind what ever connection you eant touse.. :)

C#
<connectionstrings>
   <add name="Connection1" providername="System.Data.SqlClient" connectionstring="Data Source=Server Name;Initial Catalog=Database1;User ID=Usename;Password=****" />
   <add name="Connection2" providername="System.Data.SqlClient" connectionstring="Data Source=Server Name;Initial Catalog=Database2;User ID=Usename;Password=****" />
 </connectionstrings>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900