I have a ASP.NET Web application project in which when ever user login , according to User logged in, we get have different connection string name from database and store that in session.
In Database access Layer
I have created a class with name ShareSession
public class ShareSession
{
public string ConnectionString1 { get; set; }
public string ConnectionString2 { get; set; }
public ShareSession()
{
try
{
ConnectionString1 = Convert.ToString(HttpContext.Current.Session["ConnectionStringname1"]);
ConnectionString2 = Convert.ToString(HttpContext.Current.Session["ConnectionStringname2"]);
}
catch (Exception)
{
HttpContext.Current.Response.Redirect("~/DashBoard/Login.aspx");
throw;
}
}
}
While accessing this object i just create object of this class.
ShareSession objShareSession = new ShareSession();
var Connection_Database = Convert.ToString(objShareSession.ConnectionString1);
using (SqlConnection conn = new SqlConnection(Convert.ToString(ConfigurationManager.ConnectionStrings[Connection_Database].ConnectionString)))
{
// Database Logic
}
It is performing slow is there any other solution for it.
Scenario:- i am setting dynamic connection string name from database everytime when use login it has different region database for normalization if one login from india then his data will be inserted in indian database if he login from USA then his data is inserted into USA database , in this condition how can i send this dynamic name of connection to data access layer