using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace GetBigTable
{
	class Class2
	{
		public static void GetVarcharmax()
		{
			using (SqlConnection conn = new SqlConnection("server=.;integrated security=sspi;database=adventureworks"))
			using (SqlCommand cmd = new SqlCommand("select * from bigtable", conn))
			{
				SqlDataReader rdr = null;
				SqlTransaction tx = null;

				conn.Open();
				tx = conn.BeginTransaction();
				cmd.Transaction = tx;
				rdr = cmd.ExecuteReader(CommandBehavior.SequentialAccess);

				char[] buf = new char[20000];

				rdr.Read();
				rdr.GetInt32(0);
				Console.WriteLine("Read row {0} partial", rdr[0]);
				rdr.GetChars(1, 0, buf, 0, 20000);
				Console.ReadLine();
				while (rdr.Read())
					Console.WriteLine("Read row {0}", rdr[0]);
				rdr.Close();
				tx.Commit();
			}

		}
	}
}
