コード例 #1
0
        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);
            }
        }
コード例 #2
0
 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);
     }
 }