Click here to Skip to main content
15,891,828 members
Please Sign up or sign in to vote.
2.33/5 (3 votes)
See more:
how to connect a all connection string in one connection in web.config file
Posted
Comments
Al Moje 8-Feb-12 3:04am    
Not clear, Please elaborate more...
Herman<T>.Instance 8-Feb-12 3:30am    
define different name for each connectionstring

in side connection string in web.config file


C#
<connectionStrings>
    <add name="ConnectionString" connectionString="Data Source=192.168.1.4;Database =BaryNew ;User ID=sa;Password=baryons1"/>
    <add name="BISConnectionString" connectionString="Data Source=192.168.1.4;Database =Bary ;User ID=sa;Password=baryons1"/>
    <add name="BaryConnectionString" connectionString="Data Source=WIN-3U37PS1RHVF;Initial Catalog=Bary123;Integrated Security=True" providerName="System.Data.SqlClient"/>
  </connectionStrings>
 
Share this answer
 
v2
Comments
uspatel 8-Feb-12 7:53am    
[EDIT]: pre tag added......
Tech Code Freak 8-Feb-12 12:26pm    
5up!
C#
<connectionstrings>
       <add connectionstring="Data Source=.\SQLEXPRESS;AttachDbFilename=E:\PatientDetails.mdf;Integrated Security=True;User Instance=True" name="Connection" />
    <add connectionstring="Data Source=.\SQLEXPRESS;AttachDbFilename=D:\PatientDetails.mdf;Integrated Security=True;User Instance=True" name="Connection1" />
    <add connectionstring="Data Source=.\SQLEXPRESS;AttachDbFilename=G:\PatientDetails.mdf;Integrated Security=True;User Instance=True" name="Connection2" />
  </connectionstrings>


From the code you can access like

#c#
string=Convert.ToString(ConfigurationManager.ConnectionStrings[0]); 
OR

#c#
string=Convert.ToString(ConfigurationManager.ConnectionStrings[1]); 
OR

#c#
string=Convert.ToString(ConfigurationManager.ConnectionStrings[2]); 
 
Share this answer
 
Comments
Tech Code Freak 8-Feb-12 12:27pm    
5up!

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