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 }
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 }
private void FillClose(bool isrecordset, object value) { OleDbHResult hr; if (isrecordset) { Bid.Trace("<oledb.Recordset15.Close|API|ADODB>\n"); hr = ((UnsafeNativeMethods.Recordset15)value).Close(); // MDAC 78415 Bid.Trace("<oledb.Recordset15.Close|API|ADODB|RET> %08X{HRESULT}\n", hr); } else { Bid.Trace("<oledb._ADORecord.Close|API|ADODB>\n"); hr = ((UnsafeNativeMethods._ADORecord)value).Close(); // MDAC 78415 Bid.Trace("<oledb._ADORecord.Close|API|ADODB|RET> %08X{HRESULT}\n", hr); } if ((0 < (int)hr) && (ODB.ADODB_AlreadyClosedError != (int)hr)) { UnsafeNativeMethods.IErrorInfo errorInfo = null; UnsafeNativeMethods.GetErrorInfo(0, out errorInfo); string message = String.Empty; if (null != errorInfo) { OleDbHResult hresult = ODB.GetErrorDescription(errorInfo, hr, out message); } throw new COMException(message, (int)hr); } }
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) { // 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 if (null != connection) { connection.OnInfoMessage(errorInfo, hresult); } else { } Marshal.ReleaseComObject(errorInfo); } else if (0 < hresult) { // @devnote: OnInfoMessage with no ErrorInfo } 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); }
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 OleDbError(UnsafeNativeMethods.IErrorRecords errorRecords, int index) { OleDbHResult hr; int lcid = System.Globalization.CultureInfo.CurrentCulture.LCID; UnsafeNativeMethods.IErrorInfo errorInfo = errorRecords.GetErrorInfo(index, lcid); if (null != errorInfo) { hr = errorInfo.GetDescription(out this.message); if (OleDbHResult.DB_E_NOLOCALE == hr) { Marshal.ReleaseComObject(errorInfo); lcid = Interop.Kernel32.GetUserDefaultLCID(); errorInfo = errorRecords.GetErrorInfo(index, lcid); if (null != errorInfo) { hr = errorInfo.GetDescription(out this.message); } } if ((hr < 0) && ADP.IsEmpty(this.message)) { this.message = ODB.FailedGetDescription(hr); } if (null != errorInfo) { hr = errorInfo.GetSource(out this.source); if (OleDbHResult.DB_E_NOLOCALE == hr) { Marshal.ReleaseComObject(errorInfo); lcid = Interop.Kernel32.GetUserDefaultLCID(); errorInfo = errorRecords.GetErrorInfo(index, lcid); if (null != errorInfo) { hr = errorInfo.GetSource(out this.source); } } if ((hr < 0) && ADP.IsEmpty(this.source)) { this.source = ODB.FailedGetSource(hr); } Marshal.ReleaseComObject(errorInfo !); } } UnsafeNativeMethods.ISQLErrorInfo sqlErrorInfo; errorRecords.GetCustomErrorObject(index, ref ODB.IID_ISQLErrorInfo, out sqlErrorInfo); if (null != sqlErrorInfo) { this.nativeError = sqlErrorInfo.GetSQLInfo(out this.sqlState); Marshal.ReleaseComObject(sqlErrorInfo); } }
private void SetLastErrorInfo(OleDbHResult lastErrorHr) { UnsafeNativeMethods.IErrorInfo ppIErrorInfo = null; string message = string.Empty; if ((UnsafeNativeMethods.GetErrorInfo(0, out ppIErrorInfo) == OleDbHResult.S_OK) && (ppIErrorInfo != null)) { ODB.GetErrorDescription(ppIErrorInfo, lastErrorHr, out message); } this.lastErrorFromProvider = new COMException(message, (int)lastErrorHr); }
internal static OleDbHResult GetErrorDescription(UnsafeNativeMethods.IErrorInfo errorInfo, OleDbHResult hresult, out string message) { OleDbHResult hr = errorInfo.GetDescription(out message); if (((int)hr < 0) && ADP.IsEmpty(message)) { message = FailedGetDescription(hr) + Environment.NewLine + ODB.ELookup(hresult); } if (ADP.IsEmpty(message)) { message = ODB.ELookup(hresult); } return(hr); }
private void SetLastErrorInfo(OleDbHResult lastErrorHr) { // note: OleDbHResult is actually a simple wrapper over HRESULT with OLEDB-specific codes UnsafeNativeMethods.IErrorInfo errorInfo = null; string message = String.Empty; OleDbHResult errorInfoHr = UnsafeNativeMethods.GetErrorInfo(0, out errorInfo); // 0 - IErrorInfo exists, 1 - no IErrorInfo if ((errorInfoHr == OleDbHResult.S_OK) && (errorInfo != null)) { ODB.GetErrorDescription(errorInfo, lastErrorHr, out message); // note that either GetErrorInfo or GetErrorDescription might fail in which case we will have only the HRESULT value in exception message } lastErrorFromProvider = new COMException(message, (int)lastErrorHr); }
internal static OleDbHResult GetErrorDescription(UnsafeNativeMethods.IErrorInfo errorInfo, OleDbHResult hresult, out string message) { Bid.Trace("<oledb.IErrorInfo.GetDescription|API|OS>\n"); OleDbHResult description = errorInfo.GetDescription(out message); Bid.Trace("<oledb.IErrorInfo.GetDescription|API|OS|RET> %08X{HRESULT}, Message='%ls'\n", description, message); if ((description < OleDbHResult.S_OK) && ADP.IsEmpty(message)) { message = FailedGetDescription(description) + Environment.NewLine + ELookup(hresult); } if (ADP.IsEmpty(message)) { message = ELookup(hresult); } return(description); }
static internal OleDbHResult GetErrorDescription(UnsafeNativeMethods.IErrorInfo errorInfo, OleDbHResult hresult, out string message) { Bid.Trace("<oledb.IErrorInfo.GetDescription|API|OS>\n"); OleDbHResult hr = errorInfo.GetDescription(out message); Bid.Trace("<oledb.IErrorInfo.GetDescription|API|OS|RET> %08X{HRESULT}, Message='%ls'\n", hr, message); if (((int)hr < 0) && ADP.IsEmpty(message)) { message = FailedGetDescription(hr) + Environment.NewLine + ODB.ELookup(hresult); } if (ADP.IsEmpty(message)) { message = ODB.ELookup(hresult); } return(hr); }
internal OleDbErrorCollection(UnsafeNativeMethods.IErrorInfo errorInfo) { ArrayList items = new ArrayList(); UnsafeNativeMethods.IErrorRecords errorRecords = (errorInfo as UnsafeNativeMethods.IErrorRecords); if (null != errorRecords) { int recordCount = errorRecords.GetRecordCount(); for (int i = 0; i < recordCount; ++i) { OleDbError error = new OleDbError(errorRecords, i); items.Add(error); } } this.items = items; }
static internal OleDbException CreateException(UnsafeNativeMethods.IErrorInfo errorInfo, OleDbHResult errorCode, Exception inner) // MDAC 84364 { OleDbErrorCollection errors = new OleDbErrorCollection(errorInfo); string message = null; string source = null; OleDbHResult hr = 0; if (null != errorInfo) { hr = errorInfo.GetDescription(out message); Bid.Trace("<oledb.IErrorInfo.GetDescription|API|OS|RET> %08X{HRESULT}, Description='%ls'\n", hr, message); hr = errorInfo.GetSource(out source); Bid.Trace("<oledb.IErrorInfo.GetSource|API|OS|RET> %08X{HRESULT}, Source='%ls'\n", hr, source); } int count = errors.Count; if (0 < errors.Count) { StringBuilder builder = new StringBuilder(); if ((null != message) && (message != errors[0].Message)) // WebData 103032 { builder.Append(message.TrimEnd(ODB.ErrorTrimCharacters)); // MDAC 73707 if (1 < count) { builder.Append(Environment.NewLine); } } for (int i = 0; i < count; ++i) { if (0 < i) { builder.Append(Environment.NewLine); } builder.Append(errors[i].Message.TrimEnd(ODB.ErrorTrimCharacters)); // MDAC 73707 } message = builder.ToString(); } if (ADP.IsEmpty(message)) { message = ODB.NoErrorMessage(errorCode); // MDAC 71170 } return(new OleDbException(message, inner, source, errorCode, errors)); }
internal OleDbErrorCollection(UnsafeNativeMethods.IErrorInfo errorInfo) { ArrayList list = new ArrayList(); Bid.Trace("<oledb.IUnknown.QueryInterface|API|OS> IErrorRecords\n"); UnsafeNativeMethods.IErrorRecords errorRecords = errorInfo as UnsafeNativeMethods.IErrorRecords; if (errorRecords != null) { int recordCount = errorRecords.GetRecordCount(); Bid.Trace("<oledb.IErrorRecords.GetRecordCount|API|OS|RET> RecordCount=%d\n", recordCount); for (int i = 0; i < recordCount; i++) { OleDbError error = new OleDbError(errorRecords, i); list.Add(error); } } this.items = list; }
static internal OleDbException CreateException(UnsafeNativeMethods.IErrorInfo errorInfo, OleDbHResult errorCode, Exception inner) { OleDbErrorCollection errors = new OleDbErrorCollection(errorInfo); string message = null; string source = null; OleDbHResult hr = 0; if (null != errorInfo) { hr = errorInfo.GetDescription(out message); hr = errorInfo.GetSource(out source); } int count = errors.Count; if (0 < errors.Count) { StringBuilder builder = new StringBuilder(); if ((null != message) && (message != errors[0].Message)) { builder.Append(message.TrimEnd(ODB.ErrorTrimCharacters)); if (1 < count) { builder.Append(Environment.NewLine); } } for (int i = 0; i < count; ++i) { if (0 < i) { builder.Append(Environment.NewLine); } builder.Append(errors[i].Message.TrimEnd(ODB.ErrorTrimCharacters)); } message = builder.ToString(); } if (ADP.IsEmpty(message)) { message = ODB.NoErrorMessage(errorCode); } return(new OleDbException(message, inner, source, errorCode, errors)); }
private void FillClose(bool isrecordset, object value) { OleDbHResult hr; if (isrecordset) { hr = ((UnsafeNativeMethods.Recordset15)value).Close(); } else { hr = ((UnsafeNativeMethods._ADORecord)value).Close(); } if ((0 < (int)hr) && (ODB.ADODB_AlreadyClosedError != (int)hr)) { UnsafeNativeMethods.IErrorInfo errorInfo = null; UnsafeNativeMethods.GetErrorInfo(0, out errorInfo); string message = string.Empty; throw new COMException(message, (int)hr); } }
internal OleDbException(UnsafeNativeMethods.IErrorInfo errorInfo, int errorCode, Exception inner) : base("", inner) { // copy error information into this structure so that it can be serialized by value this.oledbErrors = new OleDbErrorCollection((UnsafeNativeMethods.IErrorRecords)errorInfo); if (null != errorInfo) { // message #if DEBUG ODB.Trace_Begin(4, "IErrorInfo", "GetDescription"); #endif errorInfo.GetDescription(out this.message); #if DEBUG ODB.Trace_End(4, "IErrorInfo", "GetDescription", 0, this.message); #endif this.message = OleDbErrorCollection.BuildFullMessage(Errors, this.message); if (ADP.IsEmpty(this.message)) { this.message = ODB.NoErrorMessage(errorCode); // MDAC 71170 } // source #if DEBUG ODB.Trace_Begin(4, "IErrorInfo", "GetSource"); #endif errorInfo.GetSource(out this.source); #if DEBUG ODB.Trace_End(4, "IErrorInfo", "GetSource", 0, this.source); #endif if (null == this.source) { this.source = ""; } } HResult = errorCode; }
/// <include file='doc\OleDbError.uex' path='docs/doc[@for="OleDbError.GetErrorInfo"]/*' /> private void GetErrorInfo(UnsafeNativeMethods.IErrorRecords errorRecords, int index) { int lcid = System.Globalization.CultureInfo.CurrentCulture.LCID; UnsafeNativeMethods.IErrorInfo errorInfo = null; int hr = errorRecords.GetErrorInfo(index, lcid, out errorInfo); if ((0 <= hr) && (null != errorInfo)) { #if DEBUG ODB.Trace_Begin(4, "IErrorInfo", "GetDescription"); #endif hr = errorInfo.GetDescription(out message); #if DEBUG ODB.Trace_End(4, "IErrorInfo", "GetDescription", hr, this.message); #endif if (ODB.DB_E_NOLOCALE == hr) { // MDAC 87303 Marshal.ReleaseComObject(errorInfo); #if DEBUG ODB.Trace_Begin(4, "Kernel32", "GetUserDefaultLCID"); #endif lcid = UnsafeNativeMethods.GetUserDefaultLCID(); #if DEBUG ODB.Trace_End(4, "Kernel32", "GetUserDefaultLCID", lcid); ODB.Trace_Begin(4, "IErrorRecords", "GetErrorInfo"); #endif hr = errorRecords.GetErrorInfo(index, lcid, out errorInfo); #if DEBUG ODB.Trace_End(4, "IErrorRecords", "GetErrorInfo", hr); #endif if ((0 <= hr) && (null != errorInfo)) { #if DEBUG ODB.Trace_Begin(4, "IErrorInfo", "GetDescription", "retry"); #endif hr = errorInfo.GetDescription(out this.message); #if DEBUG ODB.Trace_End(4, "IErrorInfo", "GetDescription", hr, this.message); #endif } } if ((hr < 0) && ADP.IsEmpty(this.message)) { this.message = ODB.FailedGetDescription(hr); } if (null != errorInfo) { #if DEBUG ODB.Trace_Begin(4, "IErrorInfo", "GetSource"); #endif hr = errorInfo.GetSource(out this.source); #if DEBUG ODB.Trace_End(4, "IErrorInfo", "GetSource", hr, this.source); #endif if (ODB.DB_E_NOLOCALE == hr) { // MDAC 87303 Marshal.ReleaseComObject(errorInfo); #if DEBUG ODB.Trace_Begin(4, "Kernel32", "GetUserDefaultLCID"); #endif lcid = UnsafeNativeMethods.GetUserDefaultLCID(); #if DEBUG ODB.Trace_End(4, "Kernel32", "GetUserDefaultLCID", lcid); ODB.Trace_Begin(4, "IErrorRecords", "GetErrorInfo"); #endif hr = errorRecords.GetErrorInfo(index, lcid, out errorInfo); #if DEBUG ODB.Trace_End(4, "IErrorRecords", "GetErrorInfo", hr); #endif if ((0 <= hr) && (null != errorInfo)) { #if DEBUG ODB.Trace_Begin(4, "IErrorInfo", "GetSource", "retry"); #endif hr = errorInfo.GetSource(out this.source); #if DEBUG ODB.Trace_End(4, "IErrorInfo", "GetSource", hr, this.source); #endif } } if ((hr < 0) && ADP.IsEmpty(this.source)) { this.source = ODB.FailedGetSource(hr); } Marshal.ReleaseComObject(errorInfo); } } }
public override void SetValue(object component, object value) { if (this.readOnly) { throw new NotSupportedException(System.Windows.Forms.SR.GetString("COM2ReadonlyProperty", new object[] { this.Name })); } if (component is ICustomTypeDescriptor) { component = ((ICustomTypeDescriptor)component).GetPropertyOwner(this); } if (((component != null) && Marshal.IsComObject(component)) && (component is UnsafeNativeMethods.IDispatch)) { if (this.valueConverter != null) { bool cancelSet = false; value = this.valueConverter.ConvertManagedToNative(value, this, ref cancelSet); if (cancelSet) { return; } } UnsafeNativeMethods.IDispatch dispatch = (UnsafeNativeMethods.IDispatch)component; System.Windows.Forms.NativeMethods.tagDISPPARAMS pDispParams = new System.Windows.Forms.NativeMethods.tagDISPPARAMS(); System.Windows.Forms.NativeMethods.tagEXCEPINFO pExcepInfo = new System.Windows.Forms.NativeMethods.tagEXCEPINFO(); pDispParams.cArgs = 1; pDispParams.cNamedArgs = 1; int[] numArray = new int[] { -3 }; GCHandle handle = GCHandle.Alloc(numArray, GCHandleType.Pinned); try { pDispParams.rgdispidNamedArgs = Marshal.UnsafeAddrOfPinnedArrayElement(numArray, 0); IntPtr ptr = Marshal.AllocCoTaskMem(0x10); SafeNativeMethods.VariantInit(new HandleRef(null, ptr)); Marshal.GetNativeVariantForObject(value, ptr); pDispParams.rgvarg = ptr; try { Guid empty = Guid.Empty; int dwMessageId = dispatch.Invoke(this.dispid, ref empty, SafeNativeMethods.GetThreadLCID(), 4, pDispParams, null, pExcepInfo, new IntPtr[1]); string message = null; if ((dwMessageId == -2147352567) && (pExcepInfo.scode != 0)) { dwMessageId = pExcepInfo.scode; message = pExcepInfo.bstrDescription; } switch (dwMessageId) { case -2147467260: case -2147221492: return; case 0: case 1: this.OnValueChanged(component, EventArgs.Empty); this.lastValue = value; return; } if (dispatch is UnsafeNativeMethods.ISupportErrorInfo) { empty = typeof(UnsafeNativeMethods.IDispatch).GUID; if (System.Windows.Forms.NativeMethods.Succeeded(((UnsafeNativeMethods.ISupportErrorInfo)dispatch).InterfaceSupportsErrorInfo(ref empty))) { UnsafeNativeMethods.IErrorInfo errorInfo = null; UnsafeNativeMethods.GetErrorInfo(0, ref errorInfo); if ((errorInfo != null) && System.Windows.Forms.NativeMethods.Succeeded(errorInfo.GetDescription(null))) { message = pBstrDescription; } } } else if (message == null) { StringBuilder lpBuffer = new StringBuilder(0x100); if (SafeNativeMethods.FormatMessage(0x1200, System.Windows.Forms.NativeMethods.NullHandleRef, dwMessageId, CultureInfo.CurrentCulture.LCID, lpBuffer, 0xff, System.Windows.Forms.NativeMethods.NullHandleRef) == 0) { message = string.Format(CultureInfo.CurrentCulture, System.Windows.Forms.SR.GetString("DispInvokeFailed", new object[] { "SetValue", dwMessageId }), new object[0]); } else { message = lpBuffer.ToString(); while (((message.Length > 0) && (message[message.Length - 1] == '\n')) || (message[message.Length - 1] == '\r')) { message = message.Substring(0, message.Length - 1); } } } throw new ExternalException(message, dwMessageId); } finally { SafeNativeMethods.VariantClear(new HandleRef(null, ptr)); Marshal.FreeCoTaskMem(ptr); } } finally { handle.Free(); } } }
/// <include file='doc\OleDbInfoMessageEvent.uex' path='docs/doc[@for="OleDbInfoMessageEventArgs.OleDbInfoMessageEventArgs"]/*' /> internal OleDbInfoMessageEventArgs(UnsafeNativeMethods.IErrorInfo errorInfo, int errorCode, object src) { this.errorInfo = errorInfo; this.errorCode = errorCode; this.src = src; }
internal OleDbError(UnsafeNativeMethods.IErrorRecords errorRecords, int index) { OleDbHResult hr; int lcid = System.Globalization.CultureInfo.CurrentCulture.LCID; Bid.Trace("<oledb.IErrorRecords.GetErrorInfo|API|OS>\n"); UnsafeNativeMethods.IErrorInfo errorInfo = errorRecords.GetErrorInfo(index, lcid); if (null != errorInfo) { Bid.Trace("<oledb.IErrorInfo.GetDescription|API|OS>\n"); hr = errorInfo.GetDescription(out this.message); Bid.Trace("<oledb.IErrorInfo.GetDescription|API|OS|RET> Message='%ls'\n", this.message); if (OleDbHResult.DB_E_NOLOCALE == hr) // MDAC 87303 { Bid.Trace("<oledb.ReleaseComObject|API|OS> ErrorInfo\n"); Marshal.ReleaseComObject(errorInfo); Bid.Trace("<oledb.Kernel32.GetUserDefaultLCID|API|OS>\n"); lcid = SafeNativeMethods.GetUserDefaultLCID(); Bid.Trace("<oledb.IErrorRecords.GetErrorInfo|API|OS> LCID=%d\n", lcid); errorInfo = errorRecords.GetErrorInfo(index, lcid); if (null != errorInfo) { Bid.Trace("<oledb.IErrorInfo.GetDescription|API|OS>\n"); hr = errorInfo.GetDescription(out this.message); Bid.Trace("<oledb.IErrorInfo.GetDescription|API|OS|RET> Message='%ls'\n", this.message); } } if ((hr < 0) && ADP.IsEmpty(this.message)) { this.message = ODB.FailedGetDescription(hr); } if (null != errorInfo) { Bid.Trace("<oledb.IErrorInfo.GetSource|API|OS>\n"); hr = errorInfo.GetSource(out this.source); Bid.Trace("<oledb.IErrorInfo.GetSource|API|OS|RET> Source='%ls'\n", this.source); if (OleDbHResult.DB_E_NOLOCALE == hr) // MDAC 87303 { Marshal.ReleaseComObject(errorInfo); Bid.Trace("<oledb.Kernel32.GetUserDefaultLCID|API|OS>\n"); lcid = SafeNativeMethods.GetUserDefaultLCID(); Bid.Trace("<oledb.IErrorRecords.GetErrorInfo|API|OS> LCID=%d\n", lcid); errorInfo = errorRecords.GetErrorInfo(index, lcid); if (null != errorInfo) { Bid.Trace("<oledb.IErrorInfo.GetSource|API|OS>\n"); hr = errorInfo.GetSource(out this.source); Bid.Trace("<oledb.IErrorInfo.GetSource|API|OS|RET> Source='%ls'\n", this.source); } } if ((hr < 0) && ADP.IsEmpty(this.source)) { this.source = ODB.FailedGetSource(hr); } Bid.Trace("<oledb.Marshal.ReleaseComObject|API|OS> ErrorInfo\n"); Marshal.ReleaseComObject(errorInfo); } } UnsafeNativeMethods.ISQLErrorInfo sqlErrorInfo; Bid.Trace("<oledb.IErrorRecords.GetCustomErrorObject|API|OS> IID_ISQLErrorInfo\n"); hr = errorRecords.GetCustomErrorObject(index, ref ODB.IID_ISQLErrorInfo, out sqlErrorInfo); if (null != sqlErrorInfo) { Bid.Trace("<oledb.ISQLErrorInfo.GetSQLInfo|API|OS>\n"); this.nativeError = sqlErrorInfo.GetSQLInfo(out this.sqlState); Bid.Trace("<oledb.ReleaseComObject|API|OS> SQLErrorInfo\n"); Marshal.ReleaseComObject(sqlErrorInfo); } }
private int FillFromADODB(Object data, object adodb, string srcTable, bool multipleResults) { Debug.Assert(null != data, "FillFromADODB: null data object"); Debug.Assert(null != adodb, "FillFromADODB: null ADODB"); Debug.Assert(!(adodb is DataTable), "call Fill( (DataTable) value)"); Debug.Assert(!(adodb is DataSet), "call Fill( (DataSet) value)"); /* * IntPtr adodbptr = ADP.PtrZero; * try { // generate a new COM Callable Wrapper around the user object so they can't ReleaseComObject on us. * adodbptr = Marshal.GetIUnknownForObject(adodb); * adodb = System.Runtime.Remoting.Services.EnterpriseServicesHelper.WrapIUnknownWithComObject(adodbptr); * } * finally { * if (ADP.PtrZero != adodbptr) { * Marshal.Release(adodbptr); * } * } */ bool closeRecordset = multipleResults; // MDAC 60332, 66668 Bid.Trace("<oledb.IUnknown.QueryInterface|API|OLEDB|ADODB> ADORecordsetConstruction\n"); UnsafeNativeMethods.ADORecordsetConstruction recordset = (adodb as UnsafeNativeMethods.ADORecordsetConstruction); UnsafeNativeMethods.ADORecordConstruction record = null; if (null != recordset) // MDAC 78415 { if (multipleResults) { // The NextRecordset method is not available on a disconnected Recordset object, where ActiveConnection has been set to NULL object activeConnection; Bid.Trace("<oledb.Recordset15.get_ActiveConnection|API|ADODB>\n"); activeConnection = ((UnsafeNativeMethods.Recordset15)adodb).get_ActiveConnection(); if (null == activeConnection) { multipleResults = false; } } } else { Bid.Trace("<oledb.IUnknown.QueryInterface|API|OLEDB|ADODB> ADORecordConstruction\n"); record = (adodb as UnsafeNativeMethods.ADORecordConstruction); if (null != record) // MDAC 78415 { multipleResults = false; // IRow implies CommandBehavior.SingleRow which implies CommandBehavior.SingleResult } } // else throw ODB.Fill_NotADODB("adodb"); /* throw later, less code here*/ int results = 0; if (null != recordset) { int resultCount = 0; bool incrementResultCount; // MDAC 59632 object[] value = new object[1]; do { string tmp = null; if (data is DataSet) { tmp = GetSourceTableName(srcTable, resultCount); } results += FillFromRecordset(data, recordset, tmp, out incrementResultCount); if (multipleResults) { value[0] = DBNull.Value; object recordsAffected; object nextresult; Bid.Trace("<oledb.Recordset15.NextRecordset|API|ADODB>\n"); OleDbHResult hr = ((UnsafeNativeMethods.Recordset15)adodb).NextRecordset(out recordsAffected, out nextresult); // MDAC 78415 Bid.Trace("<oledb.Recordset15.NextRecordset|API|ADODB|RET> %08X{HRESULT}\n", hr); if (0 > hr) { // Current provider does not support returning multiple recordsets from a single execution. if (ODB.ADODB_NextResultError != (int)hr) { UnsafeNativeMethods.IErrorInfo errorInfo = null; UnsafeNativeMethods.GetErrorInfo(0, out errorInfo); string message = String.Empty; if (null != errorInfo) { OleDbHResult hresult = ODB.GetErrorDescription(errorInfo, hr, out message); } throw new COMException(message, (int)hr); } break; } adodb = nextresult; if (null != adodb) { Bid.Trace("<oledb.IUnknown.QueryInterface|API|OLEDB|ADODB> ADORecordsetConstruction\n"); recordset = (UnsafeNativeMethods.ADORecordsetConstruction)adodb; if (incrementResultCount) { resultCount++; } continue; } } break; } while(null != recordset); if ((null != recordset) && (closeRecordset || (null == adodb))) // MDAC 59746, 60902 { FillClose(true, recordset); } } else if (null != record) { results = FillFromRecord(data, record, srcTable); if (closeRecordset) // MDAC 66668 { FillClose(false, record); // MDAC 60848 } } else { throw ODB.Fill_NotADODB("adodb"); } return(results); }
internal static void ReleaseErrorInfoObject(UnsafeNativeMethods.IErrorInfo errorInfo) { ((IDisposable)errorInfo).Dispose(); }
internal static void ReleaseErrorInfoObject(UnsafeNativeMethods.IErrorInfo errorInfo) { Marshal.ReleaseComObject(errorInfo); }
internal OleDbError(UnsafeNativeMethods.IErrorRecords errorRecords, int index) { OleDbHResult description; UnsafeNativeMethods.ISQLErrorInfo info2; int lCID = CultureInfo.CurrentCulture.LCID; Bid.Trace("<oledb.IErrorRecords.GetErrorInfo|API|OS>\n"); UnsafeNativeMethods.IErrorInfo errorInfo = errorRecords.GetErrorInfo(index, lCID); if (errorInfo != null) { Bid.Trace("<oledb.IErrorInfo.GetDescription|API|OS>\n"); description = errorInfo.GetDescription(out this.message); Bid.Trace("<oledb.IErrorInfo.GetDescription|API|OS|RET> Message='%ls'\n", this.message); if (OleDbHResult.DB_E_NOLOCALE == description) { Bid.Trace("<oledb.ReleaseComObject|API|OS> ErrorInfo\n"); Marshal.ReleaseComObject(errorInfo); Bid.Trace("<oledb.Kernel32.GetUserDefaultLCID|API|OS>\n"); lCID = SafeNativeMethods.GetUserDefaultLCID(); Bid.Trace("<oledb.IErrorRecords.GetErrorInfo|API|OS> LCID=%d\n", lCID); errorInfo = errorRecords.GetErrorInfo(index, lCID); if (errorInfo != null) { Bid.Trace("<oledb.IErrorInfo.GetDescription|API|OS>\n"); description = errorInfo.GetDescription(out this.message); Bid.Trace("<oledb.IErrorInfo.GetDescription|API|OS|RET> Message='%ls'\n", this.message); } } if ((description < OleDbHResult.S_OK) && ADP.IsEmpty(this.message)) { this.message = ODB.FailedGetDescription(description); } if (errorInfo != null) { Bid.Trace("<oledb.IErrorInfo.GetSource|API|OS>\n"); description = errorInfo.GetSource(out this.source); Bid.Trace("<oledb.IErrorInfo.GetSource|API|OS|RET> Source='%ls'\n", this.source); if (OleDbHResult.DB_E_NOLOCALE == description) { Marshal.ReleaseComObject(errorInfo); Bid.Trace("<oledb.Kernel32.GetUserDefaultLCID|API|OS>\n"); lCID = SafeNativeMethods.GetUserDefaultLCID(); Bid.Trace("<oledb.IErrorRecords.GetErrorInfo|API|OS> LCID=%d\n", lCID); errorInfo = errorRecords.GetErrorInfo(index, lCID); if (errorInfo != null) { Bid.Trace("<oledb.IErrorInfo.GetSource|API|OS>\n"); description = errorInfo.GetSource(out this.source); Bid.Trace("<oledb.IErrorInfo.GetSource|API|OS|RET> Source='%ls'\n", this.source); } } if ((description < OleDbHResult.S_OK) && ADP.IsEmpty(this.source)) { this.source = ODB.FailedGetSource(description); } Bid.Trace("<oledb.Marshal.ReleaseComObject|API|OS> ErrorInfo\n"); Marshal.ReleaseComObject(errorInfo); } } Bid.Trace("<oledb.IErrorRecords.GetCustomErrorObject|API|OS> IID_ISQLErrorInfo\n"); description = errorRecords.GetCustomErrorObject(index, ref ODB.IID_ISQLErrorInfo, out info2); if (info2 != null) { Bid.Trace("<oledb.ISQLErrorInfo.GetSQLInfo|API|OS>\n"); this.nativeError = info2.GetSQLInfo(out this.sqlState); Bid.Trace("<oledb.ReleaseComObject|API|OS> SQLErrorInfo\n"); Marshal.ReleaseComObject(info2); } }