Here's the code: I need to use the conn (the database connection string) variable in many pages.
void Session_Start(object sender, EventArgs e)
{
// Code that runs when a new session is started
ConnectionStringSettings settings1 = ConfigurationManager.ConnectionStrings["...
OleDbConnection conn = new OleDbConnection(settings1.ToString());
}
How do I reference a variable that was defined in the global.asax file using C#?
Try this
public void Application_OnStart()
{
// Code that runs when a new session is started
ConnectionStringSettings settings1 = ConfigurationManager.Connectio...
OleDbConnection conn = new OleDbConnection(settings1.ToSt...
Session["MyConnection"] = conn;
}
Then to reference it you use
Have to cast it to the right object, when returning objects.
OleDbConnection myconn =
(OleDbConnection)Session["MyConnection...
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment