MARS is newly added future in SQL 2005. In earlier version from sql2005 user are not allowed to run more than one SQL batch on an open connection at the same time but sql2005 allows the user to run more than one SQL batch on an open connection at the same time.
private void MARS_Off()
{
SqlConnection conn = new SqlConnection("Server=serverName;
Database=adventureworks;Trusted_Connection=yes;");
string sql1 = "SELECT * FROM [Person].[Address]";
string sql2 = "SELECT * FROM [Production].[TransactionHistory]";
SqlCommand cmd1 = new SqlCommand(sql1, conn);
SqlCommand cmd2 = new SqlCommand(sql2, conn);
cmd1.CommandTimeout = 500;
cmd2.CommandTimeout = 500;
conn.Open();
SqlDataReader dr1 = cmd1.ExecuteReader();
// do stuff with dr1 data
conn.Close();
conn.Open();
SqlDataReader dr2 = cmd2.ExecuteReader();
// do stuff with dr2 data
conn.Close();
}
Multiple Active Result Sets (MARS) in SQL Server 2005
Posted by
Rajesh Rolen
at
Tuesday, February 2, 2010
Labels: SQL Interview Questions , sqlserver
1 comments:
Its really good blog and written by gr8 developer...
Post a Comment