Example #1
0
        private void HandleCallback(IAsyncResult result)
        {
            SqlCommandState state = result.AsyncState as SqlCommandState;

            try
            {
                state.DataReader = state.SqlCommand.EndExecuteReader(result);
                state.SignalWaitState();
            }
            catch (Exception e)
            {
                state.Exception = e;
            }
        }
Example #2
0
        public void Execute()
        {
            string connectionString = m_configurationProvider.GetConfiguration("SqlConnectionString");

            m_dbConnection.ConnectionString = connectionString;
            using (m_dbConnection)
            {
                m_dbConnection.Open();
                using (var sqlCommand = m_dbConnection.CreateCommand())
                {
                    SqlCommandState sqlCommandState = new SqlCommandState(sqlCommand);
                    SqlParameter[]  parameters      = new SqlParameter[1];

                    sqlCommand.CommandType = CommandType.StoredProcedure;
                    sqlCommand.CommandText = GetStoredProcedureName();

                    parameters = GetParameters();
                    sqlCommand.Parameters.AddRange(parameters);
                    var sqlDataReader = sqlCommand.ExecuteReader();

/*                    var asyncResult = sqlCommand.BeginExecuteReader(new AsyncCallback(HandleCallback), sqlCommandState);
 *
 *                  // Wait for async to finish. True if successful wait, false if timedout.
 *                  if (!asyncResult.AsyncWaitHandle.WaitOne(TimeSpan.FromSeconds(m_sqlTimeoutInSeconds)))
 *                  {
 *                      // TODO: Log error message and raise event somehow.
 *                      throw new TimeoutException(String.Format("Timeout occured while waiting for {0} stored procedure",
 *                                                               StoredProcedureName.EntrepreneurHomePageDataGet));
 *                  }
 *                  if (sqlCommandState.Exception != null)
 *                  {
 *                      throw new ApplicationException("Async call returned exception. See Inner Exception for details", sqlCommandState.Exception);
 *                  }
 */
                    ParseData(sqlDataReader);
                }
            }
        }