Reusing same connection

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
 
P

Patrice

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
 
S

Sahil Malik [MVP]

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/
 

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