no we cannot connect two datareader with one connection as that connection is always remains busy to serve its datareader.
Login to rate this answer.
Shree
Answered On : Mar 17th, 2006
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.
Login to rate this answer.
AD
Answered On : Mar 23rd, 2006
You can just close the datareader instead of closing the connection.
Login to rate this answer.
Karthik
Answered On : Mar 24th, 2006
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.
Login to rate this answer.
Sathiyavathi
Answered On : Mar 24th, 2006
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";

2 Users have rated as useful.
Login to rate this answer.
Hi,
We can do
By Using Connection Pooling.
Login to rate this answer.
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
Login to rate this answer.
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";
Login to rate this answer.
Ravi
Answered On : Sep 16th, 2011
Yes, you can connect two datareader to the same datasource, but one main thing is close the first datareader before using second one then only it's possible.
The point is, we can have any number of datareaders to the same datasource, but only one of them could have an active connection at any point of time.
Login to rate this answer.
Yes, 100% you can connect. help of-- Multiple Active Result Sets (MARS).
more details with Example visit below Microsoft official website. --
http://msdn.microsoft.com/en-us/library/yf1a7f4f%28v=vs.80%29.
Thanks
Rajan Vishwakarma
Code
using System;
using System.Data;
using System.Data.SqlClient;
class Class1
{
static void Main()
{
// By default, MARS is disabled when connecting
// to a MARS-enabled host such as SQL Server 2005.
// It must be enabled in the connection string.
string connectionString = GetConnectionString();
int vendorID;
SqlDataReader productReader = null;
string vendorSQL =
"SELECT VendorId, Name FROM Purchasing.Vendor";
string productSQL =
"SELECT Production.Product.Name FROM Production.Product " +
"INNER JOIN Purchasing.ProductVendor " +
"ON Production.Product.ProductID = " +
"Purchasing.ProductVendor.ProductID " +
"WHERE Purchasing.ProductVendor.VendorID = @VendorId";
using (SqlConnection awConnection =
new SqlConnection(connectionString))
{
SqlCommand vendorCmd = new SqlCommand(vendorSQL, awConnection);
SqlCommand productCmd =
new SqlCommand(productSQL, awConnection);
productCmd.Parameters.Add("@VendorId", SqlDbType.Int);
awConnection.Open();
using (SqlDataReader vendorReader = vendorCmd.ExecuteReader())
{
while (vendorReader.Read())
{
Console.WriteLine(vendorReader["Name"]);
vendorID = (int)vendorReader["VendorId"];
productCmd.Parameters["@VendorId"].Value = vendorID;
// The following line of code requires
// a MARS-enabled connection.
productReader = productCmd.ExecuteReader();
using (productReader)
{
while (productReader.Read())
{
Console.WriteLine(" " +
productReader["Name"].ToString());
}
}
}
}
Console.WriteLine("Press any key to continue");
Console.ReadLine();
}
}
private static string GetConnectionString()
{
// To avoid storing the connection string in your code,
// you can retrive it from a configuration file.
return "Data Source=(local);Integrated Security=SSPI;" +
"Initial Catalog=AdventureWorks;MultipleActiveResultSets=True";
}
}
Login to rate this answer.