Hi,i have a asp.net web application using 4.5 ,and ms sql server 2012 as backend
which has five different database with each different login credential stored in a table
I have five different connection string in web.config as
<add name="LocalSqlServer" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true" providerName="System.Data.SqlClient"/>
<add name="MainConnStr" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|main.mdf;User Instance=true" providerName="System.Data.SqlClient"/>
etc
User will enter there login credential and i want depending upon login credential user will be connected to his/her database throughout the project.
For this i have use session object like
in signup button click event
if(user=="local")
session["connectionstring"]="LocalSqlServer"
else
{
session["connectionstring"]="MainConnStr";
}
and use this session object throughout my application like this
string strcon = ConfigurationManager.ConnectionStrings[""+session["connectionstring"]+""].ConnectionString;
SqlConnection con = new SqlConnection(strcon);
con.Open();
the above code is working for me as per to my required but i have a very big project ,
Is there any better approach to achieve My requirement or should i have to stick to the above solution.
Please someone provide me the better approach or solution to deal with this kind of scenario.