Пример использования MARS
SqlConnection cn = new SqlConnection
("SERVER= sql2005;INTEGRATED SECURITY=True;"
+ "DATABASE=AdventureWorks");
SqlCommand cmd1 =
new SqlCommand("SELECT * FROM Person.Contact", cn);
cmd1.CommandType = CommandType.Text;
try
{
cn.Open();
SqlDataReader rdr = cmd1.ExecuteReader();
while (rdr.Read())
{
if (rdr["FirstName"].ToString() == "Kim")
{
// This is using the same open connection
SqlCommand cmd2 = new SqlCommand
("SELECT * FROM HumanResources.Employee "
+ "WHERE EmployeeID = 3", cn);
cmd2.CommandType = CommandType.Text;
SqlDataReader rdr2 = cmd2.ExecuteReader();
while (rdr2.Read())
{
// Process results
}
rdr2.Close();
}
}
rdr.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
cn.Close();
}