Hi there,
I was wondering if i could use database connection code in the global.asax like the following. I'm doing my first .net web app currently.
public static DatabaseConnection Connection
{
get
{
string connectionString =
"Initial Catalog = ??????????; Integrated " +
"Security = true; Network Library = ????????; " +
"Packet Size = 4096";
return new DatabaseConnection("Data Source = ????????; " + connectionString);
}
}
Any comments would be much appreciated chaps.
Loading
Rekha SinghPosted Dec 29, 2009, 7:24 AM
protected void Page_Load(object sender, EventArgs e)
{
string connectionString = Application["ConnectionString"].ToString();
}
public class Global : System.Web.HttpApplication
{
public static readonly string ConnectionString = "connection information";
}
string connectionString = Global.ConnectionString;
- It is important to make the string a static member (you could also make a static property accessor) if you want the member to be global for the application.
*****************************************************************************If you instead use member (non-static) variables, you can use these for request state.
Please mark it Accepted if u find it helpful.
Simon BradleyPosted Dec 30, 2009, 8:28 AM