T
TJ
Hello all.
I was wondering... I'm trying my hand at writing an MVC app in .NET
2.0. I'm using code-behind to implement pretty much all my logic, and I
was wondering, how bad of a practice is it to *not* use .Close(), such
as:
public void MenuView() {
// generate menu based on Uid in sesssion
// passes back strings
string sCmd = "[sp_GetMenuItemsByUid] @uid = " +
this.sm.GetUid();
SqlCommand oCmd = new SqlCommand(sCmd, this.oConn);
this.oConn.Open();
SqlDataReader oReader = oCmd.ExecuteReader();
this.qr.AddResult("menu", oReader);
//this.oConn.Close();
}
What I'm trying to do here is pass back a handle to the SqlDataReader
oReader in the .aspx page. In order for me to be able to access the
data reader, however, I need to keep the connection open after exiting
this function.
So I was wondering... is it okay for me to depend on garbage collector
to clean up my garbage, per se? Or should I still figure out a way to
ensure closure of this resource by coding up a destructor? Any thoughts
on this are appreciated.
Thanks in advance!
-TJ
I was wondering... I'm trying my hand at writing an MVC app in .NET
2.0. I'm using code-behind to implement pretty much all my logic, and I
was wondering, how bad of a practice is it to *not* use .Close(), such
as:
public void MenuView() {
// generate menu based on Uid in sesssion
// passes back strings
string sCmd = "[sp_GetMenuItemsByUid] @uid = " +
this.sm.GetUid();
SqlCommand oCmd = new SqlCommand(sCmd, this.oConn);
this.oConn.Open();
SqlDataReader oReader = oCmd.ExecuteReader();
this.qr.AddResult("menu", oReader);
//this.oConn.Close();
}
What I'm trying to do here is pass back a handle to the SqlDataReader
oReader in the .aspx page. In order for me to be able to access the
data reader, however, I need to keep the connection open after exiting
this function.
So I was wondering... is it okay for me to depend on garbage collector
to clean up my garbage, per se? Or should I still figure out a way to
ensure closure of this resource by coding up a destructor? Any thoughts
on this are appreciated.
Thanks in advance!
-TJ