Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > ADO.NET
|
ADO.NET For discussion about ADO.NET.  Topics such as question regarding the System.Data namespace are appropriate.  Questions specific to a particular application should be posted in a forum specific to the application .
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ADO.NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 1st, 2006, 11:28 AM
Friend of Wrox
 
Join Date: Feb 2006
Posts: 133
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to gaurav_jain2403
Default DataReaders Open Problem

Hello Friends,
I want to know if it is possible to open two datareaders in same connection. If yes, How can we do it? What's the code?

Thank you,
Gaurav Jain.
__________________
Gaurav
 
Old July 1st, 2006, 03:34 PM
Authorized User
 
Join Date: Apr 2006
Posts: 79
Thanks: 1
Thanked 0 Times in 0 Posts
Send a message via AIM to anujrathi Send a message via MSN to anujrathi Send a message via Yahoo to anujrathi
Default

Hi Gaurav,

Yes u can create more than one DataReaders associated with one connection Becouse DataReader depends upon your Command object. At a perticuler time, u can associate only one DataReader with one Command object bcoz u can execute only command at a time with Command object.
As u can creae more than Command object with one Connection, so u can create more than one DataReaders also. In a simple way, u can say that Connection object gives u the path(Road) to travel & at a time, u can travel more than one vehicle.
I think, now u hav a clear idea about it!!!!!!!!!!!
 
Old July 1st, 2006, 03:40 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Unfortunately, what anujrathi describes here is not true.

With .NET 1.x you can only have one data reader open at the time. This can be problematic if, for example, you want to present related data. To continue anujrathi's analogy, a connection is a narrow street, that only allows one car in one direction....

To overcome this problem, simply open up another connection and execute your reader against that connection.

In .NET 2 and SQL Server 2005 you can use MARS (Multiple Active Result Sets) that does allow you to have two readers open against a single connection.

Google for MARS and SQL Server 2005 and you'll find plenty of hits, describing how to set up and use MARS.

Cheers,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
 
Old July 10th, 2006, 05:38 AM
vbn vbn is offline
Authorized User
 
Join Date: May 2005
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,

No, you can't. The DataReader represents only one database record at a time. We must call the Read() method to fetch each new record from the underlying database table into the memory.

For it to work, the DataReader must remain connected to a database table. We can't cache a DataReader in your server's memory, so that we cannot use it on the multiple pages or over multiple requests to the same page. If we simply need to grab some database records and quickly display them on a web page, a DataReader is useful.

Regards
bhar
http://www.vkinfotek.com









Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem when SqlConnection.Open() hoetat C# 7 July 6th, 2008 07:43 PM
2 DataReaders Open Problem gaurav_jain2403 ASP.NET 1.0 and 1.1 Professional 1 July 2nd, 2006 10:05 PM
Multiple Datareaders using the same connection malarvizhi C# 0 June 20th, 2006 06:28 AM
Two Datareaders?? hexOffender VB Databases Basics 0 March 22nd, 2006 04:17 PM
executing 2 datareaders msrnivas .NET Web Services 2 January 8th, 2004 08:15 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.