コード例 #1
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);
                }
            }
        }
コード例 #2
0
        private void FillClose(bool isrecordset, object value)
        {
            OleDbHResult result;

            if (isrecordset)
            {
                Bid.Trace("<oledb.Recordset15.Close|API|ADODB>\n");
                result = ((System.Data.Common.UnsafeNativeMethods.Recordset15)value).Close();
                Bid.Trace("<oledb.Recordset15.Close|API|ADODB|RET> %08X{HRESULT}\n", result);
            }
            else
            {
                Bid.Trace("<oledb._ADORecord.Close|API|ADODB>\n");
                result = ((System.Data.Common.UnsafeNativeMethods._ADORecord)value).Close();
                Bid.Trace("<oledb._ADORecord.Close|API|ADODB|RET> %08X{HRESULT}\n", result);
            }
            if ((OleDbHResult.S_OK < result) && (((OleDbHResult)(-2146824584)) != result))
            {
                System.Data.Common.UnsafeNativeMethods.IErrorInfo ppIErrorInfo = null;
                System.Data.Common.UnsafeNativeMethods.GetErrorInfo(0, out ppIErrorInfo);
                string message = string.Empty;
                if (ppIErrorInfo != null)
                {
                    ODB.GetErrorDescription(ppIErrorInfo, result, out message);
                }
                throw new COMException(message, (int)result);
            }
        }
コード例 #3
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);
        }
コード例 #4
0
        internal static OleDbException CreateException(System.Data.Common.UnsafeNativeMethods.IErrorInfo errorInfo, OleDbHResult errorCode, Exception inner)
        {
            OleDbErrorCollection errors   = new OleDbErrorCollection(errorInfo);
            string       pBstrDescription = null;
            string       pBstrSource      = null;
            OleDbHResult description      = OleDbHResult.S_OK;

            if (errorInfo != null)
            {
                description = errorInfo.GetDescription(out pBstrDescription);
                Bid.Trace("<oledb.IErrorInfo.GetDescription|API|OS|RET> %08X{HRESULT}, Description='%ls'\n", description, pBstrDescription);
                description = errorInfo.GetSource(out pBstrSource);
                Bid.Trace("<oledb.IErrorInfo.GetSource|API|OS|RET> %08X{HRESULT}, Source='%ls'\n", description, pBstrSource);
            }
            int count = errors.Count;

            if (0 < errors.Count)
            {
                StringBuilder builder = new StringBuilder();
                if ((pBstrDescription != null) && (pBstrDescription != errors[0].Message))
                {
                    builder.Append(pBstrDescription.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));
                }
                pBstrDescription = builder.ToString();
            }
            if (ADP.IsEmpty(pBstrDescription))
            {
                pBstrDescription = ODB.NoErrorMessage(errorCode);
            }
            return(new OleDbException(pBstrDescription, inner, pBstrSource, errorCode, errors));
        }
コード例 #5
0
        private int FillFromADODB(object data, object adodb, string srcTable, bool multipleResults)
        {
            string sourceTableName;
            bool   flag2;
            bool   flag = multipleResults;

            Bid.Trace("<oledb.IUnknown.QueryInterface|API|OLEDB|ADODB> ADORecordsetConstruction\n");
            System.Data.Common.UnsafeNativeMethods.ADORecordsetConstruction recordset = adodb as System.Data.Common.UnsafeNativeMethods.ADORecordsetConstruction;
            System.Data.Common.UnsafeNativeMethods.ADORecordConstruction    record    = null;
            if (recordset != null)
            {
                if (multipleResults)
                {
                    Bid.Trace("<oledb.Recordset15.get_ActiveConnection|API|ADODB>\n");
                    if (((System.Data.Common.UnsafeNativeMethods.Recordset15)adodb).get_ActiveConnection() == null)
                    {
                        multipleResults = false;
                    }
                }
            }
            else
            {
                Bid.Trace("<oledb.IUnknown.QueryInterface|API|OLEDB|ADODB> ADORecordConstruction\n");
                record = adodb as System.Data.Common.UnsafeNativeMethods.ADORecordConstruction;
                if (record != null)
                {
                    multipleResults = false;
                }
            }
            int num = 0;

            if (recordset == null)
            {
                if (record == null)
                {
                    throw ODB.Fill_NotADODB("adodb");
                }
                num = this.FillFromRecord(data, record, srcTable);
                if (flag)
                {
                    this.FillClose(false, record);
                }
                return(num);
            }
            int index = 0;

            object[] objArray = new object[1];
Label_0068:
            sourceTableName = null;
            if (data is DataSet)
            {
                sourceTableName = GetSourceTableName(srcTable, index);
            }
            num += this.FillFromRecordset(data, recordset, sourceTableName, out flag2);
            if (multipleResults)
            {
                object obj2;
                object obj4;
                objArray[0] = DBNull.Value;
                Bid.Trace("<oledb.Recordset15.NextRecordset|API|ADODB>\n");
                OleDbHResult result = ((System.Data.Common.UnsafeNativeMethods.Recordset15)adodb).NextRecordset(out obj4, out obj2);
                Bid.Trace("<oledb.Recordset15.NextRecordset|API|ADODB|RET> %08X{HRESULT}\n", result);
                if (OleDbHResult.S_OK > result)
                {
                    if (((OleDbHResult)(-2146825037)) != result)
                    {
                        System.Data.Common.UnsafeNativeMethods.IErrorInfo ppIErrorInfo = null;
                        System.Data.Common.UnsafeNativeMethods.GetErrorInfo(0, out ppIErrorInfo);
                        string message = string.Empty;
                        if (ppIErrorInfo != null)
                        {
                            ODB.GetErrorDescription(ppIErrorInfo, result, out message);
                        }
                        throw new COMException(message, (int)result);
                    }
                }
                else
                {
                    adodb = obj2;
                    if (adodb != null)
                    {
                        Bid.Trace("<oledb.IUnknown.QueryInterface|API|OLEDB|ADODB> ADORecordsetConstruction\n");
                        recordset = (System.Data.Common.UnsafeNativeMethods.ADORecordsetConstruction)adodb;
                        if (flag2)
                        {
                            index++;
                        }
                        if (recordset != null)
                        {
                            goto Label_0068;
                        }
                    }
                }
            }
            if ((recordset != null) && (flag || (adodb == null)))
            {
                this.FillClose(true, recordset);
            }
            return(num);
        }