Example #1
0
        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;
        }
 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;
 }