0

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.

Zaki Mohammed
  • 969
  • 14
  • 24
  • possible duplicate of [MultipleActiveResultSets=True or multiple connections?](http://stackoverflow.com/questions/510899/multipleactiveresultsets-true-or-multiple-connections) – fubo Jun 22 '15 at 08:48
  • What makes you think the code you've posted is _actually using_ the MARS functionality? I would expect that calling `DataTable.Load` on a `SqlDataReader` to read it right to the end, and it therefore no longer be "active". – James Thorpe Jun 22 '15 at 08:56
  • I am performing a read on the same connection without making MultipleActiveResultSets so it should come up with an error, that is not happening – Zaki Mohammed Jun 22 '15 at 08:59

0 Answers0