Example #1
0
        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);
            }
        }
        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);
            }
        }
Example #3
0
        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);
        }
Example #4
0
        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);
        }
        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;
                if (null != errorInfo)
                {
                    OleDbHResult hresult = ODB.GetErrorDescription(errorInfo, hr, out message);
                }
                throw new COMException(message, (int)hr);
            }
        }
Example #6
0
        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);
        }
        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);
        }