Example #1
0
        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);
            }
        }
Example #2
0
        /// <include file='doc\OleDbError.uex' path='docs/doc[@for="OleDbError.GetSQLErrorInfo"]/*' />
        private void GetSQLErrorInfo(UnsafeNativeMethods.IErrorRecords errorRecords, int index) {
            UnsafeNativeMethods.ISQLErrorInfo sqlErrorInfo = null;            
            int hr = errorRecords.GetCustomErrorObject(index, ODB.IID_ISQLErrorInfo, out sqlErrorInfo);
            if ((0 <= hr) && (null != sqlErrorInfo)) {

                this.sqlState = null;
                this.nativeError = 0;
#if DEBUG
                ODB.Trace_Begin(4, "ISQLErrorInfo", "GetSQLInfo");
#endif
                sqlErrorInfo.GetSQLInfo(out this.sqlState, out nativeError);
#if DEBUG
                ODB.Trace_End(4, "ISQLErrorInfo", "GetSQLInfo", 0);
#endif
            }
        }
Example #3
0
        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;
        }
Example #4
0
        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;
        }
Example #5
0
        /// <include file='doc\OleDbErrorCollection.uex' path='docs/doc[@for="OleDbErrorCollection.OleDbErrorCollection"]/*' />
        internal OleDbErrorCollection(UnsafeNativeMethods.IErrorRecords errorRecords)
        {
            if (null != errorRecords)
            {
                int recordCount;
#if DEBUG
                ODB.Trace_Begin(4, "IErrorRecords", "GetRecordCount");
#endif
                int hr = errorRecords.GetRecordCount(out recordCount);
#if DEBUG
                ODB.Trace_End(4, "IErrorRecords", "GetRecordCount", hr, "Count=" + recordCount);
#endif
                if ((0 <= hr) && (0 < recordCount))
                {
                    for (int i = 0; i < recordCount; ++i)
                    {
                        items.Add(new OleDbError(errorRecords, i));
                    }
                }
            }
        }
        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);
            }
        }
Example #7
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);
            }
        }
Example #8
0
        /// <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);
                }
            }
        }
Example #9
0
 /// <include file='doc\OleDbError.uex' path='docs/doc[@for="OleDbError.OleDbError"]/*' />
 internal OleDbError(UnsafeNativeMethods.IErrorRecords errorRecords, int index) {
     // populate this structure so that we can marshal by value
     GetErrorInfo(errorRecords, index);
     GetSQLErrorInfo(errorRecords, index);
 }