using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Data.SqlClient; namespace ConsoleApplication1 { class Program { static int counter = 0; static void Main(string[] args) { SqlConnectionStringBuilder cs = new SqlConnectionStringBuilder(); cs.DataSource = @"."; cs.InitialCatalog = "UpsertTestDatabase"; cs.IntegratedSecurity = true; cs.AsynchronousProcessing = true; string connectionString = cs.ToString(); string sql = @"s_incrementMytable"; for (int i = 0; i < 100000; i++) { SqlConnection conn = new SqlConnection(connectionString); conn.Open(); SqlCommand cmd = new SqlCommand(sql, conn); cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.Parameters.Add("@id", System.Data.SqlDbType.Int).Value = i / 10; cmd.BeginExecuteNonQuery(new AsyncCallback(EndExecution), cmd); } Console.WriteLine(string.Format(@"Error count: {0}", counter)); } static void EndExecution(IAsyncResult c) { SqlCommand endCmd = (c.AsyncState as SqlCommand); try { endCmd.EndExecuteNonQuery(c); } catch (Exception ex) { //counter++; Interlocked.Increment(ref counter); Console.WriteLine(ex.Message); } finally { endCmd.Connection.Close(); } } } }