using System;
using System.Data;
using System.Data.SqlClient;

namespace MARS
{
	/// <summary>
	/// Summary description for Class1.
	/// </summary>
	class Class1
	{
		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		[STAThread]
		static void Main(string[] args)
		{
			SqlConnection conn = new SqlConnection("server=.;integrated security=sspi;database=AdventureWorks;");
			SqlTransaction tx = null, tx2 = null;
			SqlCommand cmd = new SqlCommand("select * from person.ContactType", conn);
			SqlCommand cmd2 = new SqlCommand("select * from person.AddressType", conn);

			conn.Open();

			//tx = conn.BeginTransaction();
			//cmd.Transaction = tx;
			// No parallel transactions in SQL Server 2005
			//tx2 = conn.BeginTransaction ();
			//cmd2.Transaction = tx2;
			// first reader
			SqlDataReader rdr = cmd.ExecuteReader();

			// second reader, same connection
			SqlDataReader rdr2 = cmd2.ExecuteReader();
      
      // read as long as both readers have something
			if (true)
			{
				try
				{
					while ((rdr.Read() == true) && (rdr2.Read() == true))
					{
						object []os = new object[rdr.FieldCount];
						rdr.GetValues(os);
						foreach(object o in os)
						{
							Console.WriteLine(o);
						}
						for(int i = 0; i<rdr2.FieldCount;i++)
						{
							Console.WriteLine(rdr2[i]);
						}
					}
				}
				catch (Exception e)
				{
					Console.WriteLine(e.Message);
					Console.WriteLine(e.StackTrace);
				}
				finally
				{
					cmd.Dispose();
					cmd2.Dispose();
					conn.Dispose();
				}
			}
		}
	}
}
