I have got the idea of MultipleActiveResultSets
; problem is that even if i dont make it true
in my Connection String it still do work. If it works properly without making MultipleActiveResultSets=true
why we still do need it?
Following is my code:
Controls: 2 DataGridView and One Button "button1"
Objects: 2 SqlCommand, 2 SqlDataReader, 2 DataTable, 1 SqlConnection
private void button1_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection(@"Data Source=COMP18-PC;Initial Catalog=Company;Integrated Security=True;Pooling=False");
SqlCommand com1 = new SqlCommand("select * from emp", conn);
SqlCommand com2 = new SqlCommand("select * from dept", conn);
SqlDataReader dr1;
SqlDataReader dr2;
conn.Open();
dr1 = com1.ExecuteReader();
DataTable dt1 = new DataTable();
dt1.Load(dr1);
dataGridView1.DataSource = dt1;
dr2 = com2.ExecuteReader();
DataTable dt2 = new DataTable();
dt2.Load(dr2);
dataGridView2.DataSource = dt2;
conn.Close();
}
This code works perfectly fine even though i haven't used MultipleActiveResultSet
in the connection string.
I have even taken the same SqlDataReader
for both the queries and even same SqlCommand
but it works fine. So where we have to use MultipleActiveResultSets?
My problem is not about "when to use it?" its about I am not using it when I have to but it doesnt show me any error.