Gokul's Blog

Open 100 SQL Connections to test Connection Pool Issue + C#

Leave a comment

class Program
   {
       static int iLoopStart = 0;
       static int iLoopEnd = 250;

       static void Main(string[] args)
       {

           ExecuteDBRead();
           Console.WriteLine(“Exiting Program… Y/N”);
           string sUserInput = Console.ReadLine();
           if(sUserInput.ToLower()==”n”)
               ExecuteDBRead();

       }

       private static void ExecuteDBRead()
       {
           SqlConnection myConn;
           SqlDataReader myReader = null;

           SqlCommand cmd;
           int iLoop=0;
           try
           {
               for (iLoop = iLoopStart; iLoop < iLoopStart + iLoopEnd; iLoop++)
               {
                   //using (myConn = new SqlConnection(“Data Source=tul1ciddb12;Initial Catalog=chinook;user id=ingest; pwd=ingest”))
                   //{
                   myConn = new SqlConnection(“Data Source=tul1ciddb12;Initial Catalog=chinook;user id=ingest; pwd=ingest”);
                   myConn.Open();
                   cmd = new SqlCommand(“select top 2 * from Track”, myConn);
                   using (myReader = cmd.ExecuteReader())
                   {
                       while (myReader.Read())
                       {
                           Console.WriteLine(“LoopID:{2} Track Id:{0}, Name:{1}”, myReader[0], myReader[1], iLoop);
                       }
                   }

                   cmd = null;
                   //}

               }
           }
           catch (Exception ex)
           {
               Console.WriteLine(“LoopID:{0} Error: {1}………………………………………..”,iLoop, ex.Message.ToString());
           }
           iLoopStart = iLoop;
           Console.WriteLine(“Press Enter to Continue…”);
           string sUserInput = Console.ReadLine();
           if (sUserInput == “”)
               ExecuteDBRead();

       }
   }

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s