GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  Microsoft  >  Ado.NET
Go To First  |  Previous Question  |  Next Question 
 Ado.NET  |  Question 4 of 31    Print  
can we connect two datareader to same data source using single connection at same time?
No, we cann't since once connection to database is opened must be closed before you reopen again .


  
Total Answers and Comments: 8 Last Update: June 27, 2008     Asked by: Niranjan 
  
 Sponsored Links

 
 Best Rated Answer
Submitted by: Sathiyavathi
 

 We can do it in ADO.Net 2.0 as

   In your connection string there is an additional attribute named as MARS

and set it as true. MARS stands for Multiple Active Result Sets.

  Ex :

    string connectionString = "Data Source=MSSQL1;" +
    "Initial Catalog=AdventureWorks;Integrated Security=SSPI" +
    "MultipleActiveResultSets=True";



Above answer was rated as good by the following members:
dvsnraju_mek
December 23, 2005 08:25:48   #1  
vishalsharma Member Since: December 2005   Contribution: 10    

RE: can we connect two datareader to same data source ...
no we cannot connect two datareader with one connection as that connection is always remains busy to serve its datareader.
 
Is this answer useful? Yes | NoAnswer is useful 0   Answer is not useful 1Overall Rating: -1    
March 17, 2006 11:58:29   #2  
Shree        

RE: can we connect two datareader to same data source ...
No. You will get a runtime error:// System.InvalidOperationException: There is already an open DataReader associated with this Connection which must be closed first.//SO Connection has to be closed before it is used for another DataReader.
 
Is this answer useful? Yes | NoAnswer is useful 0   Answer is not useful 1Overall Rating: -1    
March 23, 2006 13:40:49   #3  
AD        

RE: can we connect two datareader to same data source ...

You can just close the datareader instead of closing the connection.


 
Is this answer useful? Yes | NoAnswer is useful 0   Answer is not useful 1Overall Rating: -1    
March 24, 2006 01:24:24   #4  
Karthik        

RE: can we connect two datareader to same data source ...

Yes you can connect two datareader to the same datasource but one mainthing is close the first datareader before using second one then only it's possible.


 
Is this answer useful? Yes | No
March 24, 2006 07:38:23   #5  
Sathiyavathi        

RE: can we connect two datareader to same data source ...

We can do it in ADO.Net 2.0 as

In your connection string there is an additional attribute named as MARS

and set it as true. MARS stands for Multiple Active Result Sets.

Ex :

string connectionString Data Source MSSQL1; +
Initial Catalog AdventureWorks;Integrated Security SSPI +
MultipleActiveResultSets True ;


 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 0Overall Rating: +1    
March 29, 2007 11:47:45   #6  
sahu Member Since: December 2005   Contribution: 323    

RE: can we connect two datareader to same data source ...
Hi

We can do


By Using Connection Pooling.


 
Is this answer useful? Yes | No
September 20, 2007 09:12:38   #7  
ashu.fouzdar Member Since: September 2007   Contribution: 1    

RE: can we connect two datareader to same data source ...
It is bit ambiguous there are two scenerios
(1) want to connect two datareader to single database .
(2) want to connect two datareader to single database using single connection.

In first scenerio it is possible to connect two datareader to single database using different connection.
But in second scenerio it is not possible to connect two datareader to single database connection

 
Is this answer useful? Yes | No
June 27, 2008 10:47:18   #8  
dvsnraju_mek Member Since: June 2008   Contribution: 1    

RE: can we connect two datareader to same data source using single connection at same time?
yes we can connect two dataadaters to same datasource using single connection at same time.
There is a technology in ado.net 2.0 called MARS usinng Mars in connection string we can do it.
for eg:
cn.ConnectionString "server (local); database employee; integrated security sspi; MultipleActiveResultSets True";

 
Is this answer useful? Yes | No


 
Go To Top


 Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape