Can we connect two datareader to same data source using single connection at same time?
Can we connect two datareader to same data source using single connection at same time?
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Posted May 26, 2011, 12:36 AM
using (SqlConnection con = new SqlConnection())
{
string constr = @"Data Source=MURALIDHARAND\SQL2008R2;Initial Catalog=DestinationDB;Integrated Security=True;MultipleActiveResultSets=true";
con.ConnectionString = constr;
con.Open();
SqlCommand cmd1 = con.CreateCommand();
SqlCommand cmd2 = con.CreateCommand();
cmd1.CommandText = " select * from division";
cmd1.CommandType = CommandType.Text;
SqlDataReader reader1 = cmd1.ExecuteReader();
if (reader1.HasRows)
{
reader1.Read();
cmd2.CommandText = " select * from subdivision";
cmd2.CommandType = CommandType.Text;
SqlDataReader reader2 = cmd2.ExecuteReader();
if (reader2.HasRows)
{
MessageBox.Show("Success");
}
}
}
Hope this helps you.
shams khanPosted Aug 5, 2011, 7:22 AM
vikram thakurPosted Aug 4, 2011, 7:45 AM
MarcusPosted May 26, 2011, 12:40 AM