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 }
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 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); }
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); }
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); }