Re: Garbage Collection in .NET?
Posted by: Reggie Burnett
Date: January 31, 2005 12:28PM

Timothy

You have a couple of problems in the code you posted.

#1: if an exception is thrown during the while(reader.Read()) loop, you will not close the reader
#2: and this is not really a problem but you should use a finally block to close things up. Here is an alternate writing

MySqlDataReader reader = null;
try {
reader = cmd.ExecuteReader();
while (reader.Read() ) { ... }
retrn myReturnValue;
}
catch (Exception ex) {
MessageBox.Show(ex.Message);
throw;
}
finally {
if (reader != null) reader.Close();
conn.Close();
}

Options: ReplyQuote


Subject
Written By
Posted
January 26, 2005 11:05AM
Re: Garbage Collection in .NET?
January 31, 2005 12:28PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.