ExecuteReader, Connection, Data Access Application Block for .NET

  • Thread starter Thread starter j_ruez
  • Start date Start date
J

j_ruez

I cannot find any information for this question and I have looked for
about two days. Any suggestions, articles, whatever would be
appreciated.

I am using the Data Access Application Block (DAAB) to access my sql
database. I cannot figure out if I need to close any connections or
datareaders when using the SqlHelper.ExecuteReader call.

Let's say that I do the following:

SqlDataReader dtr = SqlHelper.ExecuteReader(strConnTxt,
CommandType.Text, strSql);

Once I use the datareader dtr, do I need to call the close method?
Are there any open connections that I need to worry about?

thanks
 
J,
Once I use the datareader dtr, do I need to call the close method?

Yes, you will need to close your datareader when you are done using it.
Are there any open connections that I need to worry about?

To ensure the connection gets closed when you are done using the reader,
change the myCommand.ExecuteReader() to
myCommand.ExecuteReader(CommandBehavior.CloseConnection) wherever the
datareader is being opened at, somewhere in the SqlHelper.ExecuteReader
method of the helper class. If I remember the App Blocks from MS, the
default is just (), not (CommandBehavior.CloseConnection).

HTH,

Raymond Lewallen
 
ALL connections MUST be Close'd.
Because the gc does not run right away,
it is possible to exhaust the driver's resources.
 
Back
Top