Global.asax

  • Thread starter Thread starter Ing. Leandro Pérez Guió
  • Start date Start date
I

Ing. Leandro Pérez Guió

Hello everybody:

I'm getting trouble with global.asax. Inside it, i define a sqlconnection, a
dataadapter and a dataset.

In the Session_Start i declare the session variables calls conn, da and ds.

Later, i make a webform and when i instante the session variable da, its
point to null and the ds too.

How can i make this right...

Greetings...

Leo
 
Ing. Leandro Pérez Guió said:
Hello everybody:

I'm getting trouble with global.asax. Inside it, i define a sqlconnection, a
dataadapter and a dataset.

In the Session_Start i declare the session variables calls conn, da and ds.

Later, i make a webform and when i instante the session variable da, its
point to null and the ds too.

Not sure what your aim is, but Session objects usually have to be unboxed
when you go to use them again. Your best bet would be to fully instantiate a
new object locally, and only then assign it to the session variable.

private void DoDataStuff(string ConnectionString)
{
SqlDataAdapter da = new SqlDataAdapter("select * from db",
ConnectionString);
Session["da"] = da;
//etc.
}

R.
 
Hi leandro,

I think that it's not a good idea to keep a SqlConnection on session ,
worse if you keep it open.

I instead would keep the ConnectionString and open/Close the connection on
the page as needed.

This is how you work with session variables

Session_Start ( ... )
{
//Create teh dataset
DataSet dataset = CreateDataSet();
//put it in session
Session["dataset"] = dataset;

//Get it value
DataSet copy_dataset = ( DataSet) Session["dataset"];

}


I don';t know if this make it clear for you, if not just post back the code
where you set the session variables and where you are using them.

Un Saludo desde Miami :)
 
Back
Top