Reusing same connection

  • Thread starter Thread starter Steve Schroeder
  • Start date Start date
S

Steve Schroeder

Even though I'm using:

InvoiceDataReader =
adoInvoiceProc.ExecuteReader(CommandBehavior.CloseConnection)

Later I get:

There is already an open DataReader associated with this Connection which
must be closed first.

I'd want to reuse one connection right, and not define a new one for each
DataReader, right? Keep in mind I'm Looping through the result set of one
DataReader, passing on values to another Command/DataReader object for
criteria...but wanted to use the same connection...

Thanks...I can post some code if that would make my point clearer.

Steve
 
This is something new you'll have with ADO.NET 2.0. For now you can't have
multiple datareaders open at the sme time on a single connection...


Patrice
 
1. You cannot have multiple datareaders on the same connection at the same
time - unless you use MARS - which is a SQL2k5 and ADO.NET 2.0 thing.
2. For .NET 1.1, you'll have to rely on two connections to get the
functionality you describe below.
3. OleDb will do this by opening multiple physical connections - bad bad bad
!! (Why bad? because a) You don't know a connection is open, and b)
Transactions could deadlock each other and you wouldn't know what the heck
is going on !!)

- Sahil Malik [MVP]
http://codebetter.com/blogs/sahil.malik/
 
Back
Top