Home All Groups Group Topic Archive Search About

Multiple active readers on one connection?

Author
4 Nov 2005 4:39 AM
David Thielen
Hi;

For a single DbConnection, can I call DbCommand.ExecuteReader() for several
selects and then for each reader call Read() and iterate through the rows. I
have a situation where for my outer reader, for each row I need to call a
select and iterate through the inner list of rows.

--
thanks - dave

Author
4 Nov 2005 5:34 AM
Sahil Malik [MVP]
..NET 1.1 / SQL2K world - No you can't.

There is a new and shiny thing called MARS - but I would highly recommend
understanding it's implications before you start doing it.

- Sahil Malik [MVP]
ADO.NET 2.0 book -
http://codebetter.com/blogs/sahil.malik/archive/2005/05/13/63199.aspx
----------------------------------------------------------------------------

Show quote
"David Thielen" <thielen@nospam.nospam> wrote in message
news:3088DDC3-C6B0-42BC-AEB9-EFD03777823F@microsoft.com...
> Hi;
>
> For a single DbConnection, can I call DbCommand.ExecuteReader() for
> several
> selects and then for each reader call Read() and iterate through the rows.
> I
> have a situation where for my outer reader, for each row I need to call a
> select and iterate through the inner list of rows.
>
> --
> thanks - dave
Author
4 Nov 2005 5:41 AM
David Thielen
Hi;

I'm .NET 2.0 only. Does that make a difference?

If I go the DataSet route, then can I do this?

--
thanks - dave


Show quote
"Sahil Malik [MVP]" wrote:

> ..NET 1.1 / SQL2K world - No you can't.
>
> There is a new and shiny thing called MARS - but I would highly recommend
> understanding it's implications before you start doing it.
>
> - Sahil Malik [MVP]
> ADO.NET 2.0 book -
> http://codebetter.com/blogs/sahil.malik/archive/2005/05/13/63199.aspx
> ----------------------------------------------------------------------------
>
> "David Thielen" <thielen@nospam.nospam> wrote in message
> news:3088DDC3-C6B0-42BC-AEB9-EFD03777823F@microsoft.com...
> > Hi;
> >
> > For a single DbConnection, can I call DbCommand.ExecuteReader() for
> > several
> > selects and then for each reader call Read() and iterate through the rows.
> > I
> > have a situation where for my outer reader, for each row I need to call a
> > select and iterate through the inner list of rows.
> >
> > --
> > thanks - dave
>
>
>
Author
4 Nov 2005 5:45 AM
Sahil Malik [MVP]
..NET 2.0 will allow you to do MARS, but you shouldn't abuse it as there are
many side effects you need to be careful of. Check out my other reply for
the rest of the story :).

- Sahil Malik [MVP]
ADO.NET 2.0 book -
http://codebetter.com/blogs/sahil.malik/archive/2005/05/13/63199.aspx
----------------------------------------------------------------------------



Show quote
"David Thielen" <thielen@nospam.nospam> wrote in message
news:8997BDA9-1805-494F-B428-BA91A452E8D4@microsoft.com...
> Hi;
>
> I'm .NET 2.0 only. Does that make a difference?
>
> If I go the DataSet route, then can I do this?
>
> --
> thanks - dave
>
>
> "Sahil Malik [MVP]" wrote:
>
>> ..NET 1.1 / SQL2K world - No you can't.
>>
>> There is a new and shiny thing called MARS - but I would highly recommend
>> understanding it's implications before you start doing it.
>>
>> - Sahil Malik [MVP]
>> ADO.NET 2.0 book -
>> http://codebetter.com/blogs/sahil.malik/archive/2005/05/13/63199.aspx
>> ----------------------------------------------------------------------------
>>
>> "David Thielen" <thielen@nospam.nospam> wrote in message
>> news:3088DDC3-C6B0-42BC-AEB9-EFD03777823F@microsoft.com...
>> > Hi;
>> >
>> > For a single DbConnection, can I call DbCommand.ExecuteReader() for
>> > several
>> > selects and then for each reader call Read() and iterate through the
>> > rows.
>> > I
>> > have a situation where for my outer reader, for each row I need to call
>> > a
>> > select and iterate through the inner list of rows.
>> >
>> > --
>> > thanks - dave
>>
>>
>>
Author
4 Nov 2005 5:47 AM
Kevin Yu [MSFT]
Hi Dave,

In .NET 2.0, you can use Multiple Active Result Sets to achieve this. That
is open multiple DataReader on one connection object. However, this can
only be done with SQL server 2005. Please check the following link for more
information.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnsql90/htm
l/MARSinSQL05.asp

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

AddThis Social Bookmark Button