상속: System.Data.Common.DbException
예제 #1
0
        internal static Exception?ProcessResults(OleDbHResult hresult, OleDbConnection?connection, object?src)
        {
            if ((0 <= (int)hresult) && ((null == connection) || (null == connection.Events[EventInfoMessage])))
            {
                SafeNativeMethods.Wrapper.ClearErrorInfo();
                return(null);
            }

            // ErrorInfo object is to be checked regardless the hresult returned by the function called
            Exception?   e  = null;
            OleDbHResult hr = UnsafeNativeMethods.GetErrorInfo(0, out UnsafeNativeMethods.IErrorInfo? errorInfo);  // 0 - IErrorInfo exists, 1 - no IErrorInfo

            if ((OleDbHResult.S_OK == hr) && (null != errorInfo))
            {
                try
                {
                    if (hresult < 0)
                    {
                        // UNDONE: if authentication failed - throw a unique exception object type
                        //if (/*OLEDB_Error.DB_SEC_E_AUTH_FAILED*/unchecked((int)0x80040E4D) == hr) {
                        //}
                        //else if (/*OLEDB_Error.DB_E_CANCELED*/unchecked((int)0x80040E4E) == hr) {
                        //}
                        // else {
                        e = OleDbException.CreateException(errorInfo, hresult, null);
                        //}

                        if (OleDbHResult.DB_E_OBJECTOPEN == hresult)
                        {
                            e = ADP.OpenReaderExists(e);
                        }

                        ResetState(connection);
                    }
                    else
                    {
                        connection?.OnInfoMessage(errorInfo, hresult);
                    }
                }
                finally
                {
                    UnsafeNativeMethods.ReleaseErrorInfoObject(errorInfo);
                }
            }
            else if (0 < hresult)
            {
                // @devnote: OnInfoMessage with no ErrorInfo
            }
            else if ((int)hresult < 0)
            {
                e = ODB.NoErrorInformation(connection?.Provider, hresult, null); // OleDbException

                ResetState(connection);
            }
            if (null != e)
            {
                ADP.TraceExceptionAsReturnValue(e);
            }
            return(e);
        }
예제 #2
0
        internal void OnInfoMessage(UnsafeNativeMethods.IErrorInfo errorInfo, OleDbHResult errorCode)
        {
            OleDbInfoMessageEventHandler handler = (OleDbInfoMessageEventHandler)Events[EventInfoMessage];

            if (null != handler)
            {
                try
                {
                    OleDbException            exception = OleDbException.CreateException(errorInfo, errorCode, null);
                    OleDbInfoMessageEventArgs e         = new OleDbInfoMessageEventArgs(exception);
                    handler(this, e);
                }
                catch (Exception e)
                { // eat the exception
                    // UNDONE - should not be catching all exceptions!!!
                    if (!ADP.IsCatchableOrSecurityExceptionType(e))
                    {
                        throw;
                    }

                    ADP.TraceExceptionWithoutRethrow(e);
                }
            }
#if DEBUG
            else
            {
                OleDbException exception = OleDbException.CreateException(errorInfo, errorCode, null);
            }
#endif
        }
예제 #3
0
        internal void OnInfoMessage(System.Data.Common.UnsafeNativeMethods.IErrorInfo errorInfo, OleDbHResult errorCode)
        {
            OleDbInfoMessageEventHandler handler = (OleDbInfoMessageEventHandler)base.Events[EventInfoMessage];

            if (handler != null)
            {
                try
                {
                    OleDbInfoMessageEventArgs e = new OleDbInfoMessageEventArgs(OleDbException.CreateException(errorInfo, errorCode, null));
                    if (Bid.TraceOn)
                    {
                        Bid.Trace("<oledb.OledbConnection.OnInfoMessage|API|INFO> %d#, Message='%ls'\n", this.ObjectID, e.Message);
                    }
                    handler(this, e);
                }
                catch (Exception exception)
                {
                    if (!ADP.IsCatchableOrSecurityExceptionType(exception))
                    {
                        throw;
                    }
                    ADP.TraceExceptionWithoutRethrow(exception);
                }
            }
        }
        internal void OnInfoMessage(UnsafeNativeMethods.IErrorInfo errorInfo, OleDbHResult errorCode)
        {
            OleDbInfoMessageEventHandler handler = (OleDbInfoMessageEventHandler)Events[EventInfoMessage];

            if (null != handler)
            {
                try {
                    OleDbException            exception = OleDbException.CreateException(errorInfo, errorCode, null);
                    OleDbInfoMessageEventArgs e         = new OleDbInfoMessageEventArgs(exception);
                    if (Bid.TraceOn)
                    {
                        Bid.Trace("<oledb.OledbConnection.OnInfoMessage|API|INFO> %d#, Message='%ls'\n", ObjectID, e.Message);
                    }
                    handler(this, e);
                }
                catch (Exception e) { // eat the exception
                    //
                    if (!ADP.IsCatchableOrSecurityExceptionType(e))
                    {
                        throw;
                    }

                    ADP.TraceExceptionWithoutRethrow(e);
                }
            }
#if DEBUG
            else
            {
                OleDbException exception = OleDbException.CreateException(errorInfo, errorCode, null);
                Bid.Trace("<oledb.OledbConnection.OnInfoMessage|API|INFO> %d#, Message='%ls'\n", ObjectID, exception.Message);
            }
#endif
        }
        static internal Exception ProcessResults(OleDbHResult hresult, OleDbConnection connection, object src)
        {
            if ((0 <= (int)hresult) && ((null == connection) || (null == connection.Events[EventInfoMessage])))
            {
                SafeNativeMethods.Wrapper.ClearErrorInfo();
                return(null);
            }

            // ErrorInfo object is to be checked regardless the hresult returned by the function called
            Exception e = null;

            UnsafeNativeMethods.IErrorInfo errorInfo = null;
            OleDbHResult hr = UnsafeNativeMethods.GetErrorInfo(0, out errorInfo);  // 0 - IErrorInfo exists, 1 - no IErrorInfo

            if ((OleDbHResult.S_OK == hr) && (null != errorInfo))
            {
                if (hresult < 0)
                {
                    //



                    e = OleDbException.CreateException(errorInfo, hresult, null);
                    //}

                    if (OleDbHResult.DB_E_OBJECTOPEN == hresult)
                    {
                        e = ADP.OpenReaderExists(e);
                    }

                    ResetState(connection);
                }
                else if (null != connection)
                {
                    connection.OnInfoMessage(errorInfo, hresult);
                }
                else
                {
                    Bid.Trace("<oledb.OledbConnection|WARN|INFO> ErrorInfo available, but not connection %08X{HRESULT}\n", hresult);
                }
                Marshal.ReleaseComObject(errorInfo);
            }
            else if (0 < hresult)
            {
                // @devnote: OnInfoMessage with no ErrorInfo
                Bid.Trace("<oledb.OledbConnection|ERR|INFO> ErrorInfo not available %08X{HRESULT}\n", hresult);
            }
            else if ((int)hresult < 0)
            {
                e = ODB.NoErrorInformation((null != connection) ? connection.Provider : null, hresult, null); // OleDbException

                ResetState(connection);
            }
            if (null != e)
            {
                ADP.TraceExceptionAsReturnValue(e);
            }
            return(e);
        }
예제 #6
0
 public static string DisplayOleDbErrorCollection(OleDbException exception)
 {
     string sError = "";
     for (int i = 0; i < exception.Errors.Count; i++)
     {
         sError += "Index #" + i + "\n" +
                "Message: " + exception.Errors[i].Message + "\n" +
                "Native: " + exception.Errors[i].NativeError.ToString() + "\n" +
                "Source: " + exception.Errors[i].Source + "\n" +
                "SQL: " + exception.Errors[i].SQLState + "\n";
     }
     return sError;
 }
예제 #7
0
        internal static OleDbException NoErrorInformation(string provider, OleDbHResult hr, Exception inner)
        {
            OleDbException e;

            if (!ADP.IsEmpty(provider))
            {
                e = new OleDbException(SR.Format(SR.OleDb_NoErrorInformation2, provider, ODB.ELookup(hr)), hr, inner);
            }
            else
            {
                e = new OleDbException(SR.Format(SR.OleDb_NoErrorInformation, ODB.ELookup(hr)), hr, inner);
            }
            ADP.TraceExceptionAsReturnValue(e);
            return(e);
        }
예제 #8
0
        internal static OleDbException NoErrorInformation(string provider, OleDbHResult hr, Exception inner)
        {
            OleDbException exception;

            if (!ADP.IsEmpty(provider))
            {
                exception = new OleDbException(Res.GetString("OleDb_NoErrorInformation2", new object[] { provider, ELookup(hr) }), hr, inner);
            }
            else
            {
                exception = new OleDbException(Res.GetString("OleDb_NoErrorInformation", new object[] { ELookup(hr) }), hr, inner);
            }
            ADP.TraceExceptionAsReturnValue(exception);
            return(exception);
        }
        public String RegistrarExcepcion(Exception excepcion, String origen)
        {
            string mensaje = "";

            try
            {
                if (excepcion is System.ApplicationException)
                {
                    System.ApplicationException exc = (System.ApplicationException)excepcion;
                    mensaje = EscribirApplicationException(exc, origen);
                }
                else if (excepcion is System.IO.InvalidDataException)
                {
                    System.IO.InvalidDataException exc = (System.IO.InvalidDataException)excepcion;
                    mensaje = EscribirInvalidDataException(exc, origen);
                }
                else if (excepcion is System.IO.IOException)
                {
                    System.IO.IOException exc = (System.IO.IOException)excepcion;
                    mensaje = EscribirIOEx(exc, origen);
                }
                else if (excepcion is System.FormatException)
                {
                    System.FormatException exc = excepcion as System.FormatException;
                    mensaje = EscribirFormatException(exc, origen);
                }
                else if (excepcion is System.Data.SqlClient.SqlException)
                {
                    System.Data.SqlClient.SqlException exc = excepcion as System.Data.SqlClient.SqlException;
                    mensaje = EscribirSqlEx(exc, origen);
                }
                else if (excepcion is System.Data.OleDb.OleDbException)
                {
                    System.Data.OleDb.OleDbException exc = excepcion as System.Data.OleDb.OleDbException;
                    mensaje = EscribirOleDbEx(exc, origen);
                }
                else
                {
                    mensaje = EscribirGenericEx(excepcion, origen);
                }
            }
            catch (Exception ex)
            {
                mensaje = "Error interno de la Aplicación. Por favor informar a Sopórte Técnico.\n\n";
                mensaje = mensaje + EscribirLocalEx(ex, this.ToString() + ".RegistrarExcepcion");
            }
            return(mensaje);
        }
예제 #10
0
        internal static Exception ProcessResults(OleDbHResult hresult, OleDbConnection connection, object src)
        {
            if ((OleDbHResult.S_OK <= hresult) && ((connection == null) || (connection.Events[EventInfoMessage] == null)))
            {
                SafeNativeMethods.Wrapper.ClearErrorInfo();
                return(null);
            }
            Exception e = null;

            System.Data.Common.UnsafeNativeMethods.IErrorInfo ppIErrorInfo = null;
            if ((System.Data.Common.UnsafeNativeMethods.GetErrorInfo(0, out ppIErrorInfo) == OleDbHResult.S_OK) && (ppIErrorInfo != null))
            {
                if (hresult < OleDbHResult.S_OK)
                {
                    e = OleDbException.CreateException(ppIErrorInfo, hresult, null);
                    if (OleDbHResult.DB_E_OBJECTOPEN == hresult)
                    {
                        e = ADP.OpenReaderExists(e);
                    }
                    ResetState(connection);
                }
                else if (connection != null)
                {
                    connection.OnInfoMessage(ppIErrorInfo, hresult);
                }
                else
                {
                    Bid.Trace("<oledb.OledbConnection|WARN|INFO> ErrorInfo available, but not connection %08X{HRESULT}\n", hresult);
                }
                Marshal.ReleaseComObject(ppIErrorInfo);
            }
            else if (OleDbHResult.S_OK < hresult)
            {
                Bid.Trace("<oledb.OledbConnection|ERR|INFO> ErrorInfo not available %08X{HRESULT}\n", hresult);
            }
            else if (hresult < OleDbHResult.S_OK)
            {
                e = ODB.NoErrorInformation((connection != null) ? connection.Provider : null, hresult, null);
                ResetState(connection);
            }
            if (e != null)
            {
                ADP.TraceExceptionAsReturnValue(e);
            }
            return(e);
        }
예제 #11
0
    public static void SQLErrorHandler(System.Data.OleDb.OleDbException E, Label Message)
    {
        try
        {
            Message.Style["font-size"] = "18pt";
            Message.Style["color"]     = MSG_ERROR_COLOR;
            switch (E.ErrorCode)
            {
            case -2147217873:
                Message.Text += MSG_SQL_ERROR_DUPLICATED_KEY;
                break;

            default:
                Message.Text += MSG_SQL_ERROR_OTHER_PREFIX + "[" + E.ErrorCode.ToString() + "]" + E.ToString();
                break;
            }
        }
        catch (System.Exception e)
        {
            ErrorHandler(e, Message);
            return;
        }
    }
 internal static OleDbException NoErrorInformation(string provider, OleDbHResult hr, Exception inner)
 {
     OleDbException exception;
     if (!ADP.IsEmpty(provider))
     {
         exception = new OleDbException(Res.GetString("OleDb_NoErrorInformation2", new object[] { provider, ELookup(hr) }), hr, inner);
     }
     else
     {
         exception = new OleDbException(Res.GetString("OleDb_NoErrorInformation", new object[] { ELookup(hr) }), hr, inner);
     }
     ADP.TraceExceptionAsReturnValue(exception);
     return exception;
 }
예제 #13
0
        public List<IntelWebObject> Load(string whereclause, string sortorder, List<IntelWebField> filterparams)
        {
            if (!this.User.loggedIn) { return null; }
            OleDbCommand tcommand;
            if (commandType == System.Data.CommandType.StoredProcedure)
            {
                tcommand = new OleDbCommand(this.tableName, this.connection());
            }
            else
            {
                tcommand = new OleDbCommand(this.FullSelectStatement(whereclause, sortorder), this.connection());
            }
            tcommand.CommandType = commandType;
            IntelWebParameter tempParam = new IntelWebParameter();
            if (filterparams != null)
            {
                foreach (IntelWebField apfield in filterparams)
                {
                    tcommand.Parameters.Add(apfield.parameter);
                }
            }
            List<IntelWebObject> objcol = new List<IntelWebObject>();
            try
            {
                    OleDbDataReader oread = tcommand.ExecuteReader();
                    tcommand.Parameters.Clear();

                    while (oread.Read())
                    {
                        IntelWebObject myobj = (IntelWebObject)Activator.CreateInstance(this.GetType(), new object[] { this.User, this.selectFieldsList, false });
                        this.Construct(oread, myobj);
                        objcol.Add(myobj);
                    }
                    oread.Close();
            }
            catch (OleDbException ex)
            {
                _lastDBError = ex;
                throw ex;
            }
            return objcol;
        }
예제 #14
0
 internal OleDbInfoMessageEventArgs(OleDbException exception)
 {
     Debug.Assert(null != exception, "OleDbInfoMessageEventArgs without OleDbException");
     this.exception = exception;
 }
예제 #15
0
        public virtual bool save()
        {
            string tsql = "";
            string sql2 = "";
            string finalsql = "";

            if (!this.isDirty)
            {
                return true;
            }
            if (this.primaryKey == null)
            {
                AddSaveError("The object has no primary key set.");
                return false;
            }
            _saveerrors = validateRecord();
            if (_saveerrors != null)
            {
                return false;
            }

            foreach (IntelWebField x in this.changedFields)
            {
                tsql += x.name;
                if (!this.isNew)
                {
                    tsql += " = ?";
                }
                else
                {
                    sql2 += "?,";
                }
                tsql += ",";
            }

            if (this.isNew)
            {
                foreach (IntelWebField x in this.defaultFields)
                {
                    if (!x.isAutoGenerated)
                    {
                        if (x.name.Equals("last_modified_by", StringComparison.InvariantCultureIgnoreCase))
                        {
                            x.fieldValue = this.User.userName;
                        }
                        tsql += x.name + ",";
                        sql2 += "?,";
                    }
                }
            }
            if (sql2 != "") { sql2 = sql2.Substring(0, sql2.Length - 1); }
            if (tsql != "") { tsql = tsql.Substring(0, tsql.Length - 1); }
            if (this.isNew)
            {
                finalsql = "Insert into [" + this.tableName + "] (" + tsql + ") values (" + sql2 + ")";
            }
            else
            {
                finalsql = "Update [" + this.tableName + "] set " + tsql;
            }

            OleDbCommand tCommand = new OleDbCommand(finalsql, this.connection());
            foreach (IntelWebField webfield in this.changedFields)
            {
                tCommand.Parameters.Add(webfield.parameter);
            }

            if (this.isNew)
            {
                foreach (IntelWebField webfield2 in this.defaultFields)
                {
                    //Console.Write("'" + (webfield2.fieldValue != null ? webfield2.fieldValue.ToString() : "") + "',");
                    tCommand.Parameters.Add(webfield2.parameter);
                }
            }
            else
            {
                finalsql += " where " + this.primaryKey.name + " = ?";
                tCommand.Parameters.Add(this.primaryKey.parameter);
                tCommand.CommandText = finalsql;
            }

            try
            {
                if (this.User.inTrans())
                {
                    tCommand.Transaction = this.User.dbTrans();
                }
                int returnvalue = tCommand.ExecuteNonQuery();
                tCommand.Parameters.Clear();

                setPK(this);

                this.afterSave();
                this.isDirty = false;
                this.isNew = false;

                return true;
            }
            catch (OleDbException ex)
            {
                tCommand.Parameters.Clear();
                _lastDBError = ex;
                AddSaveError(ex.Message);

                return false;
            }
        }
예제 #16
0
 public ConnectionException(OleDbException ex, string connectionString)
     : this((Exception)ex,
         connectionString)
 {
 }
        private OleDbDataReader ExecuteReaderInternal(CommandBehavior behavior, string method)
        {
            OleDbDataReader dataReader = null;
            OleDbException  previous   = null;
            int             num2       = 0;

            try
            {
                object obj2;
                int    num;
                this.ValidateConnectionAndTransaction(method);
                if ((CommandBehavior.SingleRow & behavior) != CommandBehavior.Default)
                {
                    behavior |= CommandBehavior.SingleResult;
                }
                switch (this.CommandType)
                {
                case ((System.Data.CommandType) 0):
                case System.Data.CommandType.Text:
                case System.Data.CommandType.StoredProcedure:
                    num = this.ExecuteCommand(behavior, out obj2);
                    break;

                case System.Data.CommandType.TableDirect:
                    num = this.ExecuteTableDirect(behavior, out obj2);
                    break;

                default:
                    throw ADP.InvalidCommandType(this.CommandType);
                }
                if (this._executeQuery)
                {
                    try
                    {
                        dataReader = new OleDbDataReader(this._connection, this, 0, this.commandBehavior);
                        switch (num)
                        {
                        case 0:
                            dataReader.InitializeIMultipleResults(obj2);
                            dataReader.NextResult();
                            break;

                        case 1:
                            dataReader.InitializeIRowset(obj2, ChapterHandle.DB_NULL_HCHAPTER, this._recordsAffected);
                            dataReader.BuildMetaInfo();
                            dataReader.HasRowsRead();
                            break;

                        case 2:
                            dataReader.InitializeIRow(obj2, this._recordsAffected);
                            dataReader.BuildMetaInfo();
                            break;

                        case 3:
                            if (!this._isPrepared)
                            {
                                this.PrepareCommandText(2);
                            }
                            OleDbDataReader.GenerateSchemaTable(dataReader, this._icommandText, behavior);
                            break;
                        }
                        obj2 = null;
                        this._hasDataReader = true;
                        this._connection.AddWeakReference(dataReader, 2);
                        num2 = 1;
                        return(dataReader);
                    }
                    finally
                    {
                        if (1 != num2)
                        {
                            this.canceling = true;
                            if (dataReader != null)
                            {
                                dataReader.Dispose();
                                dataReader = null;
                            }
                        }
                    }
                }
                try
                {
                    if (num == 0)
                    {
                        UnsafeNativeMethods.IMultipleResults imultipleResults = (UnsafeNativeMethods.IMultipleResults)obj2;
                        previous = OleDbDataReader.NextResults(imultipleResults, this._connection, this, out this._recordsAffected);
                    }
                }
                finally
                {
                    try
                    {
                        if (obj2 != null)
                        {
                            Marshal.ReleaseComObject(obj2);
                            obj2 = null;
                        }
                        this.CloseFromDataReader(this.ParameterBindings);
                    }
                    catch (Exception exception3)
                    {
                        if (!ADP.IsCatchableExceptionType(exception3))
                        {
                            throw;
                        }
                        if (previous == null)
                        {
                            throw;
                        }
                        previous = new OleDbException(previous, exception3);
                    }
                }
            }
            finally
            {
                try
                {
                    if ((dataReader == null) && (1 != num2))
                    {
                        this.ParameterCleanup();
                    }
                }
                catch (Exception exception2)
                {
                    if (!ADP.IsCatchableExceptionType(exception2))
                    {
                        throw;
                    }
                    if (previous == null)
                    {
                        throw;
                    }
                    previous = new OleDbException(previous, exception2);
                }
                if (previous != null)
                {
                    throw previous;
                }
            }
            return(dataReader);
        }
예제 #18
0
        public static tgConcurrencyException CheckForConcurrencyException(OleDbException ex)
        {
            tgConcurrencyException ce = null;

            if (ex.Errors != null)
            {
                foreach (OleDbError err in ex.Errors)
                {
                    if (err.NativeError == 532)
                    {
                        ce = new tgConcurrencyException(err.Message, ex);
                        ce.Source = err.Source;
                        break;
                    }
                }
            }

            return ce;
        }
 internal OleDbInfoMessageEventArgs(OleDbException exception) {
     Debug.Assert(null != exception, "OleDbInfoMessageEventArgs without OleDbException"); 
     this.exception = exception;
 }
예제 #20
0
        private OleDbDataReader ExecuteReaderInternal(CommandBehavior behavior, string method) {
            OleDbDataReader dataReader = null;
            OleDbException nextResultsFailure = null;
            int state = ODB.InternalStateClosed;
            try {
                ValidateConnectionAndTransaction(method);

                if (0 != (CommandBehavior.SingleRow & behavior)) {
                    // CommandBehavior.SingleRow implies CommandBehavior.SingleResult
                    behavior |= CommandBehavior.SingleResult;
                }

                object executeResult;
                int resultType;

                switch(CommandType) {
                case 0: // uninitialized CommandType.Text
                case CommandType.Text:
                case CommandType.StoredProcedure:
                    resultType = ExecuteCommand(behavior, out executeResult);
                    break;

                case CommandType.TableDirect:
                    resultType = ExecuteTableDirect(behavior, out executeResult);
                    break;

                default:
                    throw ADP.InvalidCommandType(CommandType);
                }

                if (_executeQuery) {
                    try {
                        dataReader = new OleDbDataReader(_connection, this, 0, this.commandBehavior);

                        switch(resultType) {
                        case ODB.ExecutedIMultipleResults:
                            dataReader.InitializeIMultipleResults(executeResult);
                            dataReader.NextResult();
                            break;
                        case ODB.ExecutedIRowset:
                            dataReader.InitializeIRowset(executeResult, ChapterHandle.DB_NULL_HCHAPTER, _recordsAffected);
                            dataReader.BuildMetaInfo();
                            dataReader.HasRowsRead();
                            break;
                        case ODB.ExecutedIRow:
                            dataReader.InitializeIRow(executeResult, _recordsAffected);
                            dataReader.BuildMetaInfo();
                            break;
                        case ODB.PrepareICommandText:
                            if (!_isPrepared) {
                                PrepareCommandText(2);
                            }
                            OleDbDataReader.GenerateSchemaTable(dataReader, _icommandText, behavior);
                            break;
                        default:
                            Debug.Assert(false, "ExecuteReaderInternal: unknown result type");
                            break;
                        }
                        executeResult = null;
                        _hasDataReader = true;
                        _connection.AddWeakReference(dataReader, OleDbReferenceCollection.DataReaderTag);

                        // command stays in the executing state until the connection
                        // has a datareader to track for it being closed
                        state = ODB.InternalStateOpen; // MDAC 72655
                    }
                    finally {
                        if (ODB.InternalStateOpen != state) {
                            this.canceling = true;
                            if (null != dataReader) {
                                ((IDisposable) dataReader).Dispose();
                                dataReader = null;
                            }
                        }
                    }
                    Debug.Assert(null != dataReader, "ExecuteReader should never return a null DataReader");
                }
                else { // optimized code path for ExecuteNonQuery to not create a OleDbDataReader object
                    try {
                        if (ODB.ExecutedIMultipleResults == resultType) {
                            UnsafeNativeMethods.IMultipleResults multipleResults = (UnsafeNativeMethods.IMultipleResults) executeResult;

                            // may cause a Connection.ResetState which closes connection
                            nextResultsFailure = OleDbDataReader.NextResults(multipleResults, _connection, this, out _recordsAffected);
                        }
                    }
                    finally {
                        try {
                            if (null != executeResult) {
                                Marshal.ReleaseComObject(executeResult);
                                executeResult = null;
                            }
                            CloseFromDataReader(ParameterBindings);
                        }
                        catch(Exception e) {
                            // 
                            if (!ADP.IsCatchableExceptionType(e)) {
                                throw;
                            }
                            if (null != nextResultsFailure) {
                                nextResultsFailure = new OleDbException(nextResultsFailure, e);
                            }
                            else {
                                throw;
                            }
                        }
                    }
                }
            }
            finally { // finally clear executing state
                try {
                    if ((null == dataReader) && (ODB.InternalStateOpen != state)) { // MDAC 67218
                        ParameterCleanup();
                    }
                }
                catch(Exception e) {
                    // 
                    if (!ADP.IsCatchableExceptionType(e)) {
                        throw;
                    }
                    if (null != nextResultsFailure) {
                        nextResultsFailure = new OleDbException(nextResultsFailure, e);
                    }
                    else {
                        throw;
                    }
                }
                if (null != nextResultsFailure) {
                    throw nextResultsFailure;
                }
            }
            return dataReader;
        }
예제 #21
0
 private void HandleOleDbException(OleDbException xcp)
 {
     Logger.Log(xcp);
     if (xcp.Message.StartsWith("Unrecognized database format"))
     {
         throw new OleDbDatabaseFormatException(
             string.Format("Database connection string: {0}", ConnectionString), xcp);
     }
     else if (xcp.Message.StartsWith("The Microsoft Jet database engine cannot find the input table or query"))
     {
         throw new OleDbMissingTableException(
             string.Format("Missing table name: {0}", TableName), xcp);
     }
     else
     {
         throw new Exception("Non specific OleDbException.", xcp);
     }
 }
        private OleDbDataReader ExecuteReaderInternal(CommandBehavior behavior, string method)
        {
            OleDbDataReader dataReader = null;
            OleDbException previous = null;
            int num2 = 0;
            try
            {
                object obj2;
                int num;
                this.ValidateConnectionAndTransaction(method);
                if ((CommandBehavior.SingleRow & behavior) != CommandBehavior.Default)
                {
                    behavior |= CommandBehavior.SingleResult;
                }
                switch (this.CommandType)
                {
                    case ((System.Data.CommandType) 0):
                    case System.Data.CommandType.Text:
                    case System.Data.CommandType.StoredProcedure:
                        num = this.ExecuteCommand(behavior, out obj2);
                        break;

                    case System.Data.CommandType.TableDirect:
                        num = this.ExecuteTableDirect(behavior, out obj2);
                        break;

                    default:
                        throw ADP.InvalidCommandType(this.CommandType);
                }
                if (this._executeQuery)
                {
                    try
                    {
                        dataReader = new OleDbDataReader(this._connection, this, 0, this.commandBehavior);
                        switch (num)
                        {
                            case 0:
                                dataReader.InitializeIMultipleResults(obj2);
                                dataReader.NextResult();
                                break;

                            case 1:
                                dataReader.InitializeIRowset(obj2, ChapterHandle.DB_NULL_HCHAPTER, this._recordsAffected);
                                dataReader.BuildMetaInfo();
                                dataReader.HasRowsRead();
                                break;

                            case 2:
                                dataReader.InitializeIRow(obj2, this._recordsAffected);
                                dataReader.BuildMetaInfo();
                                break;

                            case 3:
                                if (!this._isPrepared)
                                {
                                    this.PrepareCommandText(2);
                                }
                                OleDbDataReader.GenerateSchemaTable(dataReader, this._icommandText, behavior);
                                break;
                        }
                        obj2 = null;
                        this._hasDataReader = true;
                        this._connection.AddWeakReference(dataReader, 2);
                        num2 = 1;
                        return dataReader;
                    }
                    finally
                    {
                        if (1 != num2)
                        {
                            this.canceling = true;
                            if (dataReader != null)
                            {
                                dataReader.Dispose();
                                dataReader = null;
                            }
                        }
                    }
                }
                try
                {
                    if (num == 0)
                    {
                        UnsafeNativeMethods.IMultipleResults imultipleResults = (UnsafeNativeMethods.IMultipleResults) obj2;
                        previous = OleDbDataReader.NextResults(imultipleResults, this._connection, this, out this._recordsAffected);
                    }
                }
                finally
                {
                    try
                    {
                        if (obj2 != null)
                        {
                            Marshal.ReleaseComObject(obj2);
                            obj2 = null;
                        }
                        this.CloseFromDataReader(this.ParameterBindings);
                    }
                    catch (Exception exception3)
                    {
                        if (!ADP.IsCatchableExceptionType(exception3))
                        {
                            throw;
                        }
                        if (previous == null)
                        {
                            throw;
                        }
                        previous = new OleDbException(previous, exception3);
                    }
                }
            }
            finally
            {
                try
                {
                    if ((dataReader == null) && (1 != num2))
                    {
                        this.ParameterCleanup();
                    }
                }
                catch (Exception exception2)
                {
                    if (!ADP.IsCatchableExceptionType(exception2))
                    {
                        throw;
                    }
                    if (previous == null)
                    {
                        throw;
                    }
                    previous = new OleDbException(previous, exception2);
                }
                if (previous != null)
                {
                    throw previous;
                }
            }
            return dataReader;
        }
예제 #23
0
 static internal OleDbException NoErrorInformation(string provider, OleDbHResult hr, Exception inner) {
     OleDbException e;
     if (!ADP.IsEmpty(provider)) {
         e = new OleDbException(Res.GetString(Res.OleDb_NoErrorInformation2, provider, ODB.ELookup(hr)), hr, inner);
     }
     else {
         e = new OleDbException(Res.GetString(Res.OleDb_NoErrorInformation, ODB.ELookup(hr)), hr, inner);
     }
     ADP.TraceExceptionAsReturnValue(e);
     return e;
 }
예제 #24
0
        protected void DisplayOleDbErrorCollection(OleDbException exception)
        {
            for (int i = 0; i < exception.Errors.Count; i++)
            {
                Console.WriteLine("Index #" + i + "\n" +
                    "Message: " + exception.Errors[i].Message + "\n" +
                    "Native: " + exception.Errors[i].NativeError.ToString() + "\n" +
                    "Source: " + exception.Errors[i].Source + "\n" +
                    "SQL: " + exception.Errors[i].SQLState + "\n");
            }

            Console.ReadLine();
        }
예제 #25
0
 public Error()
 {
     ex = (OleDbException)(base.InnerException);
 }
 internal OleDbException(OleDbException previous, Exception inner) : base(previous.Message, inner)
 {
     base.HResult = previous.ErrorCode;
     this.oledbErrors = previous.oledbErrors;
 }
예제 #27
0
 public Error(string message)
 {
     ex = (OleDbException)(base.InnerException);
 }
 internal OleDbInfoMessageEventArgs(OleDbException exception)
 {
     this.exception = exception;
 }
예제 #29
0
 public Error(string message, System.Exception inner)
 {
     ex = (OleDbException)(base.InnerException);
 }
예제 #30
0
        private OleDbDataReader?ExecuteReaderInternal(CommandBehavior behavior, string method)
        {
            OleDbDataReader?dataReader         = null;
            OleDbException? nextResultsFailure = null;
            int             state = ODB.InternalStateClosed;

            try
            {
                ValidateConnectionAndTransaction(method);

                if (0 != (CommandBehavior.SingleRow & behavior))
                {
                    // CommandBehavior.SingleRow implies CommandBehavior.SingleResult
                    behavior |= CommandBehavior.SingleResult;
                }

                object?executeResult;
                int    resultType;

                switch (CommandType)
                {
                case 0:     // uninitialized CommandType.Text
                case CommandType.Text:
                case CommandType.StoredProcedure:
                    resultType = ExecuteCommand(behavior, out executeResult);
                    break;

                case CommandType.TableDirect:
                    resultType = ExecuteTableDirect(behavior, out executeResult);
                    break;

                default:
                    throw ADP.InvalidCommandType(CommandType);
                }

                if (_executeQuery)
                {
                    try
                    {
                        dataReader = new OleDbDataReader(_connection !, this, 0, this.commandBehavior);

                        switch (resultType)
                        {
                        case ODB.ExecutedIMultipleResults:
                            dataReader.InitializeIMultipleResults(executeResult);
                            dataReader.NextResult();
                            break;

                        case ODB.ExecutedIRowset:
                            dataReader.InitializeIRowset(executeResult, ChapterHandle.DB_NULL_HCHAPTER, _recordsAffected);
                            dataReader.BuildMetaInfo();
                            dataReader.HasRowsRead();
                            break;

                        case ODB.ExecutedIRow:
                            dataReader.InitializeIRow(executeResult, _recordsAffected);
                            dataReader.BuildMetaInfo();
                            break;

                        case ODB.PrepareICommandText:
                            if (!_isPrepared)
                            {
                                PrepareCommandText(2);
                            }
                            OleDbDataReader.GenerateSchemaTable(dataReader, _icommandText !, behavior);
                            break;

                        default:
                            Debug.Assert(false, "ExecuteReaderInternal: unknown result type");
                            break;
                        }
                        executeResult  = null;
                        _hasDataReader = true;
                        _connection !.AddWeakReference(dataReader, OleDbReferenceCollection.DataReaderTag);

                        // command stays in the executing state until the connection
                        // has a datareader to track for it being closed
                        state = ODB.InternalStateOpen;
                    }
                    finally
                    {
                        if (ODB.InternalStateOpen != state)
                        {
                            this.canceling = true;
                            if (null != dataReader)
                            {
                                ((IDisposable)dataReader).Dispose();
                                dataReader = null;
                            }
                        }
                    }
                    Debug.Assert(null != dataReader, "ExecuteReader should never return a null DataReader");
                }
                else
                { // optimized code path for ExecuteNonQuery to not create a OleDbDataReader object
                    try
                    {
                        if (ODB.ExecutedIMultipleResults == resultType)
                        {
                            UnsafeNativeMethods.IMultipleResults?multipleResults = (UnsafeNativeMethods.IMultipleResults?)executeResult;

                            // may cause a Connection.ResetState which closes connection
                            nextResultsFailure = OleDbDataReader.NextResults(multipleResults, _connection !, this, out _recordsAffected);
                        }
                    }
                    finally
                    {
                        try
                        {
                            if (null != executeResult)
                            {
                                Marshal.ReleaseComObject(executeResult);
                                executeResult = null;
                            }
                            CloseFromDataReader(ParameterBindings);
                        }
                        catch (Exception e)
                        {
                            // UNDONE - should not be catching all exceptions!!!
                            if (!ADP.IsCatchableExceptionType(e))
                            {
                                throw;
                            }
                            if (null != nextResultsFailure)
                            {
                                nextResultsFailure = new OleDbException(nextResultsFailure, e);
                            }
                            else
                            {
                                throw;
                            }
                        }
                    }
                }
            }
            finally
            { // finally clear executing state
                try
                {
                    if ((null == dataReader) && (ODB.InternalStateOpen != state))
                    {
                        ParameterCleanup();
                    }
                }
                catch (Exception e)
                {
                    // UNDONE - should not be catching all exceptions!!!
                    if (!ADP.IsCatchableExceptionType(e))
                    {
                        throw;
                    }
                    if (null != nextResultsFailure)
                    {
                        nextResultsFailure = new OleDbException(nextResultsFailure, e);
                    }
                    else
                    {
                        throw;
                    }
                }
                if (null != nextResultsFailure)
                {
                    throw nextResultsFailure;
                }
            }
            return(dataReader);
        }
예제 #31
0
 protected Error(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context)
 {
     ex = (OleDbException)(base.InnerException);
 }
예제 #32
0
 internal OleDbException(OleDbException previous, Exception inner) : base(previous.Message, inner)
 {
     HResult          = previous.ErrorCode;
     this.oledbErrors = previous.oledbErrors;
 }
예제 #33
0
 internal OleDbInfoMessageEventArgs(OleDbException exception)
 {
     this.exception = exception;
 }