Example #1
0
 protected bool Equals(MessageExecuteSetting other)
 {
     return(string.Equals(DataBaseInstance, other.DataBaseInstance) &&
            string.Equals(Connection, other.Connection) &&
            IsolationLevel.Equals(other.IsolationLevel));
 }
        static void Main(string[] args)
        {
            SqlConnectionStringBuilder cs = new SqlConnectionStringBuilder();

            try
            {
                readConfigFile();

                cs.DataSource      = strDBServer;
                cs.InitialCatalog  = strDBInitialCatalog;
                cs.ApplicationName = strApplicationName;


                cs.IntegratedSecurity     = true;
                cs.AsynchronousProcessing = true;
                string connectionString = cs.ToString();

                stopWatch = new Stopwatch();
                stopWatch.Start();

                SqlConnection connCleanDB = new SqlConnection(connectionString);
                connCleanDB.Open();
                SqlCommand cmdCleanTable = new SqlCommand(sqlCleanTable, connCleanDB);
                cmdCleanTable.CommandType = System.Data.CommandType.StoredProcedure;
                cmdCleanTable.ExecuteNonQuery();
                connCleanDB.Close();


                localDateStarted = DateTime.Now;

                for (int i = 1; i <= iNumberofIterations; i++)
                {
                    SqlConnection conn = new SqlConnection(connectionString);
                    conn.Open();
                    SqlCommand cmd = new SqlCommand(sqlAddData, conn);
                    cmd.CommandType = System.Data.CommandType.StoredProcedure;
                    cmd.Parameters.Add("@method", System.Data.SqlDbType.Int).Value = iMethod;
                    cmd.Parameters.Add("@id", System.Data.SqlDbType.Int).Value     = i / 10;

                    if (iTransactionIsolation.Equals(TransactionIsolationLiteral.Unspecified))
                    {
                        cmd.BeginExecuteNonQuery(new AsyncCallback(EndExecution), cmd);
                    }
                    else
                    {
                        using (new TransactionScope(TransactionScopeOption.RequiresNew, new TransactionOptions {
                            IsolationLevel = iTransactionIsolation
                        }))
                        {
                            cmd.BeginExecuteNonQuery(new AsyncCallback(EndExecution), cmd);
                        }
                    }
                }

                /*
                 *      Wait on all threads to complete
                 */
                while (iNumberofIterationsAttempted < iNumberofIterations)
                {
                    Thread.Yield();
                }


                localDateCompleted = DateTime.Now;

                stopWatch.Stop();



                // Get the elapsed time as a TimeSpan value.
                ts = stopWatch.Elapsed;

                summarize(
                    connectionString
                    , ts
                    );
            }

            catch (Exception e)
            {
                Console.WriteLine("{0} Exception caught.", e);
            }
        }