Click here to Skip to main content
15,889,858 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have Login Page through Company .If i Select One Company Then It used its Company Database seprate.if i select second Company Then it Used Second Company Database.

How Can i Do...?Help Me...Thanx In Advance
Posted
Comments
choudhary.sumit 12-Dec-12 5:36am    
what are your strategies to define connection strings. in the same page, web.cofig or a saprate layer i.e. a class??

1 solution

Hi,

Delcare all the company database connection strings in web.config like below,

<add name="ConnectionString" connectionstring="Data Source=x.x.x.x ;Initial Catalog=database1;User ID=sa;Password=sa" providername="System.Data.SqlClient" />
<add name="ConnectionString1" connectionstring="Data Source=y.y.y.y;Initial Catalog=database2;User ID=sa;Password=sa" providername="System.Data.SqlClient" />

When your login store the Company name along with user name.

When you are trying to get the connection string, use the following code,

string CompanyName = "Sam";
string conn_str = string.Empty;
if(CompanyName.Equals("Sam"))
ConfigurationSettings.AppSettings.Get("ConnectionString");
else
ConfigurationSettings.AppSettings.Get("ConnectionString1");

SqlConnection conn = new SqlConnection(conn_str);
conn.Open();
 
Share this answer
 
v2

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