Beispiel #1
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public IDbQueryResult Execute()
        {
            var _execution   = new DbQueryExecutingEventArgs();
            var _queryResult = (IDbQueryResult)null;

            if (null != Executing)
            {
                Executing(this, _execution);
            }

            if (!_execution.Cancel)
            {
                if (!_executionOnly)
                {
                    _connection.Open();
                }

                try
                {
                    _queryResult = ExecuteImpl(_command);

                    if (null != Executed)
                    {
                        Executed(this, new DbQueryExecutedEventArgs(_queryResult));
                    }
                }
                catch (SqlException ex)
                {
                    if (null != Failed)
                    {
                        var _exception = new DbQueryException(ex);
                        var _failure   = new DbQueryFailedEventArgs(_exception);

                        Failed(this, _failure);
                    }
                }
                catch (DbQueryException ex)
                {
                    if (null != Failed)
                    {
                        Failed(this, new DbQueryFailedEventArgs(ex));
                    }
                }

                if (!_executionOnly)
                {
                    _connection.Close();
                }
            }


            return(_queryResult);
        }
Beispiel #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void _OnExecuting(object sender, DbQueryExecutingEventArgs e)
        {
            e.Cancel = (State.HasFlag(DbQueryOperatingSessionStates.ConnectionFaulted) ||
                        State.HasFlag(DbQueryOperatingSessionStates.Failed));

            if (!e.Cancel)
            {
                var _sender = sender as IDbQueryContext;

                if (OperationContext.RequiresEnvironmentVariables)
                {
                    if (!_sender.ContainsParameter(ERRORCODE_PARAMETERNAME))
                    {
                        _sender.AddParameter(ERRORCODE_PARAMETERNAME, SqlDbType.Int, ERRORCODE_PARAMETERSIZE, ParameterDirection.Output);
                    }

                    if (!_sender.ContainsParameter(ERRORTEXT_PARAMETERNAME))
                    {
                        _sender.AddParameter(ERRORTEXT_PARAMETERNAME, SqlDbType.VarChar, ERRORTEXT_PARAMETERSIZE, ParameterDirection.Output);
                    }
                }
            }
        }