ExecuteReader, Connection, Data Access Application Block for .NET

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
 
R

Raymond Lewallen

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
 
Q

q

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top