I want to seperate the data module of a site into an assembly ( a single dll file ) , What is the best way to get-store and pass the ConnectionString of the site in dealing with the web application . Inside the data assembly I made a static class named ConnectionManager . It has a property named DatabaseConnectionName , that I want to pass and store the connection namewhich is inside Web.Config file . In this strategy I decided to get the name and make the connection in the load time of the website at the Global.asax file and stroe that in the property I mentioned earlier ( DatabaseConnectionName ) . But , This is just the strategy that I used , I dont know what is the common pattern for doing this job .
Parts of code : ===================================== [ ------------ Global.asax ------------ ]
the code in the site that makes the Data module accessible for the site
void Application_Start(object sender, EventArgs e)
{
OurCompany.Data.ConnectionManager.DatabaseConnectionName = "MasterConnection";
}
[ ------------ ConnectionManager Class ------------ ] this is in the data module apart from the site
public static class ConnectionManager
{
public static SqlConnection GetMasterConnection()
{
string connectionString = ConfigurationManager.ConnectionStrings[**DatabaseConnectionName**].ConnectionString;
SqlConnection conn;
//conn.Open();
conn = new SqlConnection(connectionString);
return conn;
}
private static string **databaseConnectionName**;
public static string DatabaseConnectionName
{
get
{
return databaseConnectionName;
}
set
{
databaseConnectionName = value;
}
}
== END ===========================================================
--- Questions are : ---
Where to store the connection ? ( here was a property inside the ConnectionManager Class , theCompany.Data.ConnectionManager.DatabaseConnectionName )
When make this connection ? ( here was at Global.asax Application Load time )
Which method is best for storing such information : SessionState or ViewState or a simple property
Is this strategy good ? Do you know any better way or the common pattern for this ?
Thanks for any information - MHM -