コード例 #1
0
        private void EndExecuteReaderCallBack(IAsyncResult result)
        {
            DbAsyncState state = null;

            try
            {
                // Retrieve the original command object, passed
                // to this procedure in the AsyncState property
                // of the IAsyncResult parameter.
                DaabAsyncResult blockResult = (DaabAsyncResult)result;
                state = (DbAsyncState)blockResult.AsyncState;

                state.State       = (object)state.Database.EndExecuteReader(blockResult);
                state.AsyncResult = blockResult;
            }

            catch (Exception exp)
            {
                state.Exception = exp;
            }

            finally
            {
                if (state != null)
                {
                    state.AutoResetEvent.Set();
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Finishes asynchronous execution of a Transact-SQL statement, returning an <see cref="IDataReader"/>.
        /// </summary>
        /// <param name="asyncResult">
        /// <para>The <see cref="IAsyncResult"/> returned by a call to any overload of BeginExecuteReader.</para>
        /// </param>
        /// <seealso cref="Database.ExecuteReader(DbCommand)"/>
        /// <seealso cref="BeginExecuteReader(DbCommand,AsyncCallback,object)"/>
        /// <seealso cref="BeginExecuteReader(DbCommand, DbTransaction,AsyncCallback,object)"/>
        /// <returns>
        /// <para>An <see cref="IDataReader"/> object that can be used to consume the queried information.</para>
        /// </returns>
        public override IDataReader EndExecuteReader(IAsyncResult asyncResult)
        {
            DaabAsyncResult daabAsyncResult = (DaabAsyncResult)asyncResult;
            SqlCommand      command         = (SqlCommand)daabAsyncResult.Command;

            try
            {
                IDataReader reader = command.EndExecuteReader(daabAsyncResult.InnerAsyncResult);

                return(reader);
            }
            catch (Exception)
            {
                if (command.Transaction == null)
                {
                    // for a reader, the standard cleanup will not close the connection, so it needs to be closed
                    // in the catch block if necessary
                    command.Connection.Close();
                }
                throw;
            }
            finally
            {
                CleanupConnectionFromAsyncOperation(daabAsyncResult);
            }
        }
コード例 #3
0
ファイル: SqlDatabase.cs プロジェクト: orf53975/Common
        public override IDataReader EndExecuteReader(IAsyncResult asyncResult)
        {
            DaabAsyncResult daabAsyncResult = (DaabAsyncResult)asyncResult;
            SqlCommand      command         = (SqlCommand)daabAsyncResult.Command;

            try
            {
                IDataReader reader = command.EndExecuteReader(daabAsyncResult.InnerAsyncResult);
                //instrumentationProvider.FireCommandExecutedEvent(daabAsyncResult.StartTime);

                return(reader);
            }
            catch (Exception ex)
            {
                //instrumentationProvider.FireCommandFailedEvent(command.CommandText, ConnectionStringNoCredentials, e);
                if (command.Transaction == null)
                {
                    // for a reader, the standard cleanup will not close the connection, so it needs to be closed
                    // in the catch block if necessary
                    command.Connection.Close();
                }
                throw ex;
            }
            finally
            {
                CleanupConnectionFromAsyncOperation(daabAsyncResult);
            }
        }
コード例 #4
0
        /// <summary>
        /// Finishes asynchronous execution of a Transact-SQL statement, returning the number of affected records.
        /// </summary>
        /// <param name="asyncResult">
        /// <para>The <see cref="IAsyncResult"/> returned by a call to any overload of <see cref="BeginExecuteNonQuery(DbCommand, AsyncCallback, object)"/>.</para>
        /// </param>
        /// <seealso cref="Database.ExecuteNonQuery(DbCommand)"/>
        /// <seealso cref="BeginExecuteNonQuery(DbCommand, AsyncCallback, object)"/>
        /// <seealso cref="BeginExecuteNonQuery(DbCommand, DbTransaction, AsyncCallback, object)"/>
        /// <returns>
        /// <para>The number of affected records.</para>
        /// </returns>
        public override int EndExecuteNonQuery(IAsyncResult asyncResult)
        {
            DaabAsyncResult daabAsyncResult = (DaabAsyncResult)asyncResult;
            SqlCommand      command         = (SqlCommand)daabAsyncResult.Command;

            try
            {
                int affected = command.EndExecuteNonQuery(daabAsyncResult.InnerAsyncResult);

                return(affected);
            }
            finally
            {
                CleanupConnectionFromAsyncOperation(daabAsyncResult);
            }
        }
コード例 #5
0
 private static void CleanupConnectionFromAsyncOperation(DaabAsyncResult daabAsyncResult)
 {
     if (daabAsyncResult.DisposeCommand)
     {
         if (daabAsyncResult.Command != null)
         {
             daabAsyncResult.Command.Dispose();
         }
     }
     if (daabAsyncResult.CloseConnection)
     {
         if (daabAsyncResult.Connection != null)
         {
             daabAsyncResult.Connection.Close();
         }
     }
 }
コード例 #6
0
        public void EndExecuteAccessor <T>(IAsyncResult result)
        {
            DaabAsyncResult daabResult = (DaabAsyncResult)result;
            DbAsyncState    state      = (DbAsyncState)daabResult.AsyncState;

            try
            {
                DataAccessor <T> accessor = (DataAccessor <T>)state.Accessor;
                state.State = accessor.EndExecute(result);
            }
            catch (Exception e)
            {
                state.Exception = e;
            }
            finally
            {
                state.AutoResetEvent.Set();
            }
        }
コード例 #7
0
 private static void CleanupConnectionFromAsyncOperation(DaabAsyncResult daabAsyncResult)
 {
     if (daabAsyncResult.DisposeCommand)
     {
         if (daabAsyncResult.Command != null)
         {
             daabAsyncResult.Command.Dispose();
         }
     }
     if (daabAsyncResult.CloseConnection)
     {
         if (daabAsyncResult.Connection != null)
         {
             daabAsyncResult.Connection.Close();
         }
     }
 }