Ejemplo n.º 1
0
 // IDBSchemaRowset.GetSchemas
 internal DualCoTaskMem(UnsafeNativeMethods.IDBSchemaRowset dbSchemaRowset, out int schemaCount, out IntPtr schemaGuids, out IntPtr schemaRestrictions, out OleDbHResult hr) : this() {
     Bid.Trace("<oledb.IDBSchemaRowset.GetSchemas|API|OLEDB>\n");
     hr = dbSchemaRowset.GetSchemas(out schemaCount, out base.handle, out this.handle2);
     schemaGuids = base.handle;
     schemaRestrictions = this.handle2;
     Bid.Trace("<oledb.IDBSchemaRowset.GetSchemas|API|OLEDB|RET> %08X{HRESULT}\n", hr);
 }
 internal DualCoTaskMem(UnsafeNativeMethods.IColumnsInfo columnsInfo, out IntPtr columnCount, out IntPtr columnInfos, out OleDbHResult hr) : this()
 {
     Bid.Trace("<oledb.IColumnsInfo.GetColumnInfo|API|OLEDB>\n");
     hr = columnsInfo.GetColumnInfo(out columnCount, out this.handle, out this.handle2);
     columnInfos = base.handle;
     Bid.Trace("<oledb.IColumnsInfo.GetColumnInfo|API|OLEDB|RET> %08X{HRESULT}\n", hr);
 }
Ejemplo n.º 3
0
        // IDBInfo.GetLiteralInfo
        internal DualCoTaskMem(UnsafeNativeMethods.IDBInfo dbInfo, int[] literals, out int literalCount, out IntPtr literalInfo, out OleDbHResult hr) : this() {
            int count = (null != literals) ? literals.Length : 0;

            Bid.Trace("<oledb.IDBInfo.GetLiteralInfo|API|OLEDB>\n");
            hr = dbInfo.GetLiteralInfo(count, literals, out literalCount, out base.handle, out this.handle2);
            literalInfo = base.handle;
            Bid.Trace("<oledb.IDBInfo.GetLiteralInfo|API|OLEDB|RET> %08X{HRESULT}\n", hr);
        }
 internal WrappedTransaction(UnsafeNativeMethods.ITransactionLocal transaction, int isolevel, out OleDbHResult hr) : base(transaction) {
     int transactionLevel = 0;
     Bid.Trace("<oledb.ITransactionLocal.StartTransaction|API|OLEDB>\n");
     RuntimeHelpers.PrepareConstrainedRegions();
     try { } finally {
         hr = transaction.StartTransaction(isolevel, 0, IntPtr.Zero, out transactionLevel);
         if (0 <= hr) {
             _mustComplete = true;
         }
     }
     Bid.Trace("<oledb.ITransactionLocal.StartTransaction|API|OLEDB|RET> %08X{HRESULT}\n", hr);
 }
 internal DBPropSet(UnsafeNativeMethods.IRowsetInfo properties, PropertyIDSet propidset, out OleDbHResult hr) : this()
 {
     int cPropertyIDSets = 0;
     if (propidset != null)
     {
         cPropertyIDSets = propidset.Count;
     }
     Bid.Trace("<oledb.IRowsetInfo.GetProperties|API|OLEDB>\n");
     hr = properties.GetProperties(cPropertyIDSets, propidset, out this.propertySetCount, out this.handle);
     Bid.Trace("<oledb.IRowsetInfo.GetProperties|API|OLEDB|RET> %08X{HRESULT}\n", hr);
     if (hr < OleDbHResult.S_OK)
     {
         this.SetLastErrorInfo(hr);
     }
 }
Ejemplo n.º 6
0
        internal DBPropSet(UnsafeNativeMethods.ICommandProperties properties, PropertyIDSet propidset, out OleDbHResult hr) : this() {
            Debug.Assert(null != properties, "null ICommandProperties");

            int propidsetcount = 0;
            if (null != propidset) {
                propidsetcount = propidset.Count;
            }
            Bid.Trace("<oledb.ICommandProperties.GetProperties|API|OLEDB>\n");
            hr = properties.GetProperties(propidsetcount, propidset, out this.propertySetCount, out base.handle);
            Bid.Trace("<oledb.ICommandProperties.GetProperties|API|OLEDB|RET> %08X{HRESULT}\n", hr);

            if (hr < 0) {
                // VSDD 621427: remember the last HRESULT. Note we do not want to raise exception now to avoid breaking change from Orcas RTM/SP1
                SetLastErrorInfo(hr);
            }
        }
 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);
 }
Ejemplo n.º 8
0
        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);
        }
Ejemplo n.º 9
0
        /*protected virtual*/
        internal OleDbHResult RollbackInternal(bool exceptionHandling)
        {
            OleDbHResult hr = 0;

            if (null != _transaction)
            {
                if (null != _nestedTransaction)
                {
                    OleDbTransaction?transaction = (OleDbTransaction?)_nestedTransaction.Target;
                    if ((null != transaction) && _nestedTransaction.IsAlive)
                    {
                        hr = transaction.RollbackInternal(exceptionHandling);
                        if (exceptionHandling && (hr < 0))
                        {
                            SafeNativeMethods.Wrapper.ClearErrorInfo();
                            return(hr);
                        }
                    }
                    _nestedTransaction = null;
                }
                hr = _transaction.Abort();
                _transaction.Dispose();
                _transaction = null;
                if (hr < 0)
                {
                    if (exceptionHandling)
                    {
                        ProcessResults(hr);
                    }
                    else
                    {
                        SafeNativeMethods.Wrapper.ClearErrorInfo();
                    }
                }
            }
            return(hr);
        }
Ejemplo n.º 10
0
        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);
            }
        }
Ejemplo n.º 11
0
        private static OleDbDataReader GetEnumeratorReader(object value)
        {
            System.Data.Common.NativeMethods.ISourcesRowset rowset = null;
            try
            {
                rowset = (System.Data.Common.NativeMethods.ISourcesRowset)value;
            }
            catch (InvalidCastException)
            {
                throw ODB.ISourcesRowsetNotSupported();
            }
            if (rowset == null)
            {
                throw ODB.ISourcesRowsetNotSupported();
            }
            value = null;
            int    cPropertySets = 0;
            IntPtr ptrZero       = ADP.PtrZero;

            Bid.Trace("<oledb.ISourcesRowset.GetSourcesRowset|API|OLEDB> IID_IRowset\n");
            OleDbHResult result = rowset.GetSourcesRowset(ADP.PtrZero, ODB.IID_IRowset, cPropertySets, ptrZero, out value);

            Bid.Trace("<oledb.ISourcesRowset.GetSourcesRowset|API|OLEDB|RET> %08X{HRESULT}\n", result);
            Exception exception = OleDbConnection.ProcessResults(result, null, null);

            if (exception != null)
            {
                throw exception;
            }
            OleDbDataReader reader = new OleDbDataReader(null, null, 0, CommandBehavior.Default);

            reader.InitializeIRowset(value, ChapterHandle.DB_NULL_HCHAPTER, ADP.RecordsUnaffected);
            reader.BuildMetaInfo();
            reader.HasRowsRead();
            return(reader);
        }
        private void PrepareCommandText(int expectedExecutionCount)
        {
            OleDbParameterCollection parameters = this._parameters;

            if (parameters != null)
            {
                foreach (OleDbParameter parameter in parameters)
                {
                    if (parameter.IsParameterComputed())
                    {
                        parameter.Prepare(this);
                    }
                }
            }
            System.Data.Common.UnsafeNativeMethods.ICommandPrepare prepare = this.ICommandPrepare();
            if (prepare != null)
            {
                Bid.Trace("<oledb.ICommandPrepare.Prepare|API|OLEDB> %d#, expectedExecutionCount=%d\n", this.ObjectID, expectedExecutionCount);
                OleDbHResult result = prepare.Prepare(expectedExecutionCount);
                Bid.Trace("<oledb.ICommandPrepare.Prepare|API|OLEDB|RET> %08X{HRESULT}\n", result);
                this.ProcessResults(result);
            }
            this._isPrepared = true;
        }
        private void CreateAccessor()
        {
            System.Data.Common.UnsafeNativeMethods.ICommandWithParameters commandWithParameters = this.ICommandWithParameters();
            OleDbParameterCollection parameters = this._parameters;

            OleDbParameter[] array = new OleDbParameter[parameters.Count];
            parameters.CopyTo(array, 0);
            Bindings bindings = new Bindings(array, parameters.ChangeID);

            for (int i = 0; i < array.Length; i++)
            {
                bindings.ForceRebind |= array[i].BindParameter(i, bindings);
            }
            bindings.AllocateForAccessor(null, 0, 0);
            this.ApplyParameterBindings(commandWithParameters, bindings.BindInfo);
            System.Data.Common.UnsafeNativeMethods.IAccessor iaccessor = this.IAccessor();
            OleDbHResult hr = bindings.CreateAccessor(iaccessor, 4);

            if (hr < OleDbHResult.S_OK)
            {
                this.ProcessResults(hr);
            }
            this._dbBindings = bindings;
        }
Ejemplo n.º 14
0
        internal OleDbHResult CreateCommand(ref object icommandText)
        {
            OleDbHResult result = OleDbHResult.E_NOINTERFACE;

            UnsafeNativeMethods.IDBCreateCommandCreateCommand dangerousIDBCreateCommandCreateCommand = this.DangerousIDBCreateCommandCreateCommand;
            if (dangerousIDBCreateCommandCreateCommand != null)
            {
                bool success = false;
                RuntimeHelpers.PrepareConstrainedRegions();
                try
                {
                    base.DangerousAddRef(ref success);
                    result = dangerousIDBCreateCommandCreateCommand(base.handle, IntPtr.Zero, ref ODB.IID_ICommandText, ref icommandText);
                }
                finally
                {
                    if (success)
                    {
                        base.DangerousRelease();
                    }
                }
            }
            return(result);
        }
Ejemplo n.º 15
0
        private static OleDbDataReader GetEnumeratorReader(object value)
        {
            NativeMethods.ISourcesRowset srcrowset = null;

            try
            {
                srcrowset = (NativeMethods.ISourcesRowset)value;
            }
            catch (InvalidCastException)
            {
                throw ODB.ISourcesRowsetNotSupported();
            }
            if (null == srcrowset)
            {
                throw ODB.ISourcesRowsetNotSupported();
            }
            value = null; // still held by ISourcesRowset, reused for IRowset

            int          propCount = 0;
            IntPtr       propSets  = ADP.PtrZero;
            OleDbHResult hr        = srcrowset.GetSourcesRowset(ADP.PtrZero, ODB.IID_IRowset, propCount, propSets, out value);

            Exception f = OleDbConnection.ProcessResults(hr, null, null);

            if (null != f)
            {
                throw f;
            }

            OleDbDataReader dataReader = new OleDbDataReader(null, null, 0, CommandBehavior.Default);

            dataReader.InitializeIRowset(value, ChapterHandle.DB_NULL_HCHAPTER, ADP.RecordsUnaffected);
            dataReader.BuildMetaInfo();
            dataReader.HasRowsRead();
            return(dataReader);
        }
Ejemplo n.º 16
0
        internal OleDbHResult RollbackInternal(bool exceptionHandling)
        {
            OleDbHResult hr = OleDbHResult.S_OK;

            if (this._transaction != null)
            {
                if (this._nestedTransaction != null)
                {
                    OleDbTransaction target = (OleDbTransaction)this._nestedTransaction.Target;
                    if ((target != null) && this._nestedTransaction.IsAlive)
                    {
                        hr = target.RollbackInternal(exceptionHandling);
                        if (exceptionHandling && (hr < OleDbHResult.S_OK))
                        {
                            SafeNativeMethods.Wrapper.ClearErrorInfo();
                            return(hr);
                        }
                    }
                    this._nestedTransaction = null;
                }
                hr = this._transaction.Abort();
                this._transaction.Dispose();
                this._transaction = null;
                if (hr >= OleDbHResult.S_OK)
                {
                    return(hr);
                }
                if (exceptionHandling)
                {
                    this.ProcessResults(hr);
                    return(hr);
                }
                SafeNativeMethods.Wrapper.ClearErrorInfo();
            }
            return(hr);
        }
Ejemplo n.º 17
0
        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);
                }
            }
        }
Ejemplo n.º 18
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);
        }
Ejemplo n.º 19
0
        // IDBInfo.GetLiteralInfo
        internal DualCoTaskMem(UnsafeNativeMethods.IDBInfo dbInfo, int[] literals, out int literalCount, out IntPtr literalInfo, out OleDbHResult hr) : this()
        {
            int count = (null != literals) ? literals.Length : 0;

            hr          = dbInfo.GetLiteralInfo(count, literals, out literalCount, out base.handle, out this.handle2);
            literalInfo = base.handle;
        }
Ejemplo n.º 20
0
 internal DualCoTaskMem(UnsafeNativeMethods.IColumnsInfo columnsInfo, out IntPtr columnCount, out IntPtr columnInfos, out OleDbHResult hr) : this()
 {
     Bid.Trace("<oledb.IColumnsInfo.GetColumnInfo|API|OLEDB>\n");
     hr          = columnsInfo.GetColumnInfo(out columnCount, out this.handle, out this.handle2);
     columnInfos = base.handle;
     Bid.Trace("<oledb.IColumnsInfo.GetColumnInfo|API|OLEDB|RET> %08X{HRESULT}\n", hr);
 }
Ejemplo n.º 21
0
 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;
 }
Ejemplo n.º 22
0
 internal OleDbException(string message, OleDbHResult errorCode, Exception inner) : base(message, inner)
 {
     HResult          = (int)errorCode;
     this.oledbErrors = new OleDbErrorCollection(null);
 }
 private void ProcessResultsNoReset(OleDbHResult hr)
 {
     Exception exception = OleDbConnection.ProcessResults(hr, null, this);
     if (exception != null)
     {
         throw exception;
     }
 }
Ejemplo n.º 24
0
        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;
        }
Ejemplo n.º 25
0
 internal static string FailedGetDescription(OleDbHResult errorcode)
 {
     return(SR.Format(SR.OleDb_FailedGetDescription, ODB.ELookup(errorcode)));
 }
Ejemplo n.º 26
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);
        }
Ejemplo n.º 27
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);
                }
            }
        }
Ejemplo n.º 28
0
 static internal OleDbException NoErrorInformation(string provider, OleDbHResult hr, Exception inner) {
     OleDbException e;
     if (!ADP.IsEmpty(provider)) {
         e = new OleDbException(Res.GetString(Res.OleDb_NoErrorInformation2, provider, ODB.ELookup(hr)), hr, inner);
     }
     else {
         e = new OleDbException(Res.GetString(Res.OleDb_NoErrorInformation, ODB.ELookup(hr)), hr, inner);
     }
     ADP.TraceExceptionAsReturnValue(e);
     return e;
 }
Ejemplo n.º 29
0
 private OleDbException(string message, Exception inner, string source, OleDbHResult errorCode, OleDbErrorCollection errors) : base(message, inner) { // MDAC 84364
     Debug.Assert(null != errors, "OleDbException without OleDbErrorCollection");
     Source = source;
     HResult = (int)errorCode;
     this.oledbErrors = errors;
 }
Ejemplo n.º 30
0
 // Debug error string writeline
 static internal string ELookup(OleDbHResult hr) {
     StringBuilder builder = new StringBuilder();
     builder.Append(hr.ToString());
     if ((0 < builder.Length) && Char.IsDigit(builder[0])) {
         builder.Length = 0;
     }
     builder.Append("(0x");
     builder.Append(((int)hr).ToString("X8", CultureInfo.InvariantCulture));
     builder.Append(")");
     return builder.ToString();
 }       
Ejemplo n.º 31
0
 // IDBSchemaRowset.GetSchemas
 internal DualCoTaskMem(UnsafeNativeMethods.IDBSchemaRowset dbSchemaRowset, out int schemaCount, out IntPtr schemaGuids, out IntPtr schemaRestrictions, out OleDbHResult hr) : this()
 {
     hr                 = dbSchemaRowset.GetSchemas(out schemaCount, out base.handle, out this.handle2);
     schemaGuids        = base.handle;
     schemaRestrictions = this.handle2;
 }
Ejemplo n.º 32
0
        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
        }
Ejemplo n.º 33
0
        internal DBPropSet(UnsafeNativeMethods.ICommandProperties properties, PropertyIDSet propidset, out OleDbHResult hr) : this()
        {
            Debug.Assert(null != properties, "null ICommandProperties");

            int propidsetcount = 0;

            if (null != propidset)
            {
                propidsetcount = propidset.Count;
            }
            hr = properties.GetProperties(propidsetcount, propidset, out this.propertySetCount, out base.handle);

            if (hr < 0)
            {
                // remember the last HRESULT. Note we do not want to raise exception now to avoid breaking change from Orcas RTM/SP1
                SetLastErrorInfo(hr);
            }
        }
Ejemplo n.º 34
0
 internal DualCoTaskMem(UnsafeNativeMethods.IColumnsRowset icolumnsRowset, out IntPtr cOptColumns, out OleDbHResult hr) : base(IntPtr.Zero, true) {
     Bid.Trace("<oledb.IColumnsRowset.GetAvailableColumns|API|OLEDB>\n");
     hr = icolumnsRowset.GetAvailableColumns(out cOptColumns, out base.handle);
     Bid.Trace("<oledb.IColumnsRowset.GetAvailableColumns|API|OLEDB|RET> %08X{HRESULT}\n", hr);
 }
Ejemplo n.º 35
0
        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);
        }
Ejemplo n.º 36
0
 private void ProcessResults(OleDbHResult hr) {
     Exception e;
     if (null != _command) {
         e = OleDbConnection.ProcessResults(hr, _connection, _command);
     }
     else {
         e = OleDbConnection.ProcessResults(hr, _connection, _connection);
     }
     if (null != e) { throw e; }
 }
Ejemplo n.º 37
0
 static internal string FailedGetDescription(OleDbHResult errorcode) {
     return Res.GetString(Res.OleDb_FailedGetDescription, ODB.ELookup(errorcode));
 }
Ejemplo n.º 38
0
 internal DualCoTaskMem(UnsafeNativeMethods.IDBSchemaRowset dbSchemaRowset, out int schemaCount, out IntPtr schemaGuids, out IntPtr schemaRestrictions, out OleDbHResult hr) : this()
 {
     Bid.Trace("<oledb.IDBSchemaRowset.GetSchemas|API|OLEDB>\n");
     hr                 = dbSchemaRowset.GetSchemas(out schemaCount, out this.handle, out this.handle2);
     schemaGuids        = base.handle;
     schemaRestrictions = this.handle2;
     Bid.Trace("<oledb.IDBSchemaRowset.GetSchemas|API|OLEDB|RET> %08X{HRESULT}\n", hr);
 }
Ejemplo n.º 39
0
 internal DualCoTaskMem(UnsafeNativeMethods.IColumnsRowset icolumnsRowset, out IntPtr cOptColumns, out OleDbHResult hr) : base(IntPtr.Zero, true)
 {
     Bid.Trace("<oledb.IColumnsRowset.GetAvailableColumns|API|OLEDB>\n");
     hr = icolumnsRowset.GetAvailableColumns(out cOptColumns, out this.handle);
     Bid.Trace("<oledb.IColumnsRowset.GetAvailableColumns|API|OLEDB|RET> %08X{HRESULT}\n", hr);
 }
Ejemplo n.º 40
0
            internal WrappedTransaction(UnsafeNativeMethods.ITransactionLocal transaction, int isolevel, out OleDbHResult hr) : base(transaction)
            {
                int transactionLevel = 0;

                RuntimeHelpers.PrepareConstrainedRegions();
                try
                { }
                finally
                {
                    hr = transaction.StartTransaction(isolevel, 0, IntPtr.Zero, out transactionLevel);
                    if (0 <= hr)
                    {
                        _mustComplete = true;
                    }
                }
            }
Ejemplo n.º 41
0
        internal DualCoTaskMem(UnsafeNativeMethods.IDBInfo dbInfo, int[] literals, out int literalCount, out IntPtr literalInfo, out OleDbHResult hr) : this()
        {
            int cLiterals = (literals != null) ? literals.Length : 0;

            Bid.Trace("<oledb.IDBInfo.GetLiteralInfo|API|OLEDB>\n");
            hr          = dbInfo.GetLiteralInfo(cLiterals, literals, out literalCount, out this.handle, out this.handle2);
            literalInfo = base.handle;
            Bid.Trace("<oledb.IDBInfo.GetLiteralInfo|API|OLEDB|RET> %08X{HRESULT}\n", hr);
        }
Ejemplo n.º 42
0
 static internal string FailedGetSource(OleDbHResult errorcode) {
     return Res.GetString(Res.OleDb_FailedGetSource, ODB.ELookup(errorcode));
 }
Ejemplo n.º 43
0
            internal WrappedTransaction(UnsafeNativeMethods.ITransactionLocal transaction, int isolevel, out OleDbHResult hr) : base(transaction)
            {
                int pulTransactionLevel = 0;

                Bid.Trace("<oledb.ITransactionLocal.StartTransaction|API|OLEDB>\n");
                RuntimeHelpers.PrepareConstrainedRegions();
                try
                {
                }
                finally
                {
                    hr = transaction.StartTransaction(isolevel, 0, IntPtr.Zero, out pulTransactionLevel);
                    if (OleDbHResult.S_OK <= hr)
                    {
                        this._mustComplete = true;
                    }
                }
                Bid.Trace("<oledb.ITransactionLocal.StartTransaction|API|OLEDB|RET> %08X{HRESULT}\n", hr);
            }
 private void ProcessResults(OleDbHResult hr)
 {
     Exception exception;
     if (this._command != null)
     {
         exception = OleDbConnection.ProcessResults(hr, this._connection, this._command);
     }
     else
     {
         exception = OleDbConnection.ProcessResults(hr, this._connection, this._connection);
     }
     if (exception != null)
     {
         throw exception;
     }
 }
 private Exception ExecuteCommandTextSpecialErrorHandling(OleDbHResult hr, Exception e)
 {
     if (((OleDbHResult.DB_E_ERRORSOCCURRED == hr) || (OleDbHResult.DB_E_BADBINDINFO == hr)) && (this._dbBindings != null))
     {
         StringBuilder builder = new StringBuilder();
         this.ParameterBindings.ParameterStatus(builder);
         e = ODB.CommandParameterStatus(builder.ToString(), e);
     }
     return e;
 }
Ejemplo n.º 46
0
 private void ProcessResultsNoReset(OleDbHResult hr) {
     Exception e = OleDbConnection.ProcessResults(hr, null, this);
     if (null != e) { throw e; }
 }
Ejemplo n.º 47
0
        internal OleDbConnectionInternal(OleDbConnectionString constr, OleDbConnection connection) : base()
        {
            Debug.Assert((null != constr) && !constr.IsEmpty, "empty connectionstring");
            ConnectionString = constr;

            if (constr.PossiblePrompt && !System.Environment.UserInteractive)
            {
                throw ODB.PossiblePromptNotUserInteractive();
            }

            try
            {
                // this is the native DataLinks object which pools the native datasource/session
                OleDbServicesWrapper wrapper = OleDbConnectionInternal.GetObjectPool();
                _datasrcwrp = new DataSourceWrapper();

                // DataLinks wrapper will call IDataInitialize::GetDataSource to create the DataSource
                // uses constr.ActualConnectionString, no InfoMessageEvent checking
                wrapper.GetDataSource(constr, ref _datasrcwrp);
                Debug.Assert(!_datasrcwrp.IsInvalid, "bad DataSource");

                // initialization is delayed because of OleDbConnectionStringBuilder only wants
                // pre-Initialize IDBPropertyInfo & IDBProperties on the data source
                if (null != connection)
                {
                    _sessionwrp = new SessionWrapper();

                    // From the DataSource object, will call IDBInitialize.Initialize & IDBCreateSession.CreateSession
                    // We always need both called so we use a single call for a single DangerousAddRef/DangerousRelease pair.
                    OleDbHResult hr = _datasrcwrp.InitializeAndCreateSession(constr, ref _sessionwrp);

                    // process the HResult here instead of from the SafeHandle because the possibility
                    // of an InfoMessageEvent.
                    if ((0 <= hr) && !_sessionwrp.IsInvalid)
                    { // process infonessage events
                        OleDbConnection.ProcessResults(hr, connection, connection);
                    }
                    else
                    {
                        Exception e = OleDbConnection.ProcessResults(hr, null, null);
                        Debug.Assert(null != e, "CreateSessionError");
                        throw e;
                    }
                    Debug.Assert(!_sessionwrp.IsInvalid, "bad Session");
                }
            }
            catch
            {
                if (null != _sessionwrp)
                {
                    _sessionwrp.Dispose();
                    _sessionwrp = null;
                }
                if (null != _datasrcwrp)
                {
                    _datasrcwrp.Dispose();
                    _datasrcwrp = null;
                }
                throw;
            }
        }
Ejemplo n.º 48
0
 private void ExecuteCommandTextErrorHandling(OleDbHResult hr) {
     Exception e = OleDbConnection.ProcessResults(hr, _connection, this);
     if (null != e) {
         e = ExecuteCommandTextSpecialErrorHandling(hr, e);
         throw e;
     }
 }
Ejemplo n.º 49
0
 // IColumnsInfo.GetColumnInfo
 internal DualCoTaskMem(UnsafeNativeMethods.IColumnsInfo columnsInfo, out IntPtr columnCount, out IntPtr columnInfos, out OleDbHResult hr) : this()
 {
     hr          = columnsInfo.GetColumnInfo(out columnCount, out base.handle, out this.handle2);
     columnInfos = base.handle;
 }
Ejemplo n.º 50
0
        private Exception ExecuteCommandTextSpecialErrorHandling(OleDbHResult hr, Exception e) {
            if (((OleDbHResult.DB_E_ERRORSOCCURRED == hr) || (OleDbHResult.DB_E_BADBINDINFO == hr)) && (null != _dbBindings)) { // MDAC 66026, 67039
                //
                // this code exist to try for a better user error message by post-morten detection
                // of invalid parameter types being passed to a provider that doesn't understand
                // the user specified parameter OleDbType

                Debug.Assert(null != e, "missing inner exception");

                StringBuilder builder = new StringBuilder();
                ParameterBindings.ParameterStatus(builder);
                e = ODB.CommandParameterStatus(builder.ToString(), e);
            }
            return e;
        }
Ejemplo n.º 51
0
 internal DualCoTaskMem(UnsafeNativeMethods.IColumnsRowset icolumnsRowset, out IntPtr cOptColumns, out OleDbHResult hr) : base(IntPtr.Zero, true)
 {
     hr = icolumnsRowset.GetAvailableColumns(out cOptColumns, out base.handle);
 }
 internal OleDbException(string message, OleDbHResult errorCode, Exception inner) : base(message, inner)
 {
     base.HResult = (int) errorCode;
     this.oledbErrors = new OleDbErrorCollection(null);
 }
Ejemplo n.º 53
0
 internal static string NoErrorMessage(OleDbHResult errorcode)
 {
     return(SR.Format(SR.OleDb_NoErrorMessage, ODB.ELookup(errorcode)));
 }
 private OleDbException(string message, Exception inner, string source, OleDbHResult errorCode, OleDbErrorCollection errors) : base(message, inner)
 {
     this.Source = source;
     base.HResult = (int) errorCode;
     this.oledbErrors = errors;
 }
Ejemplo n.º 55
0
 internal static string FailedGetSource(OleDbHResult errorcode)
 {
     return(SR.Format(SR.OleDb_FailedGetSource, ODB.ELookup(errorcode)));
 }
 private void ProcessResults(OleDbHResult hr) {
     OleDbConnection connection = Connection; // get value from weakref only once
     Exception e = OleDbConnection.ProcessResults(hr, connection, connection);
     if (null != e) { throw e; }
 }
Ejemplo n.º 57
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;

            UnsafeNativeMethods.ADORecordsetConstruction?recordset = (adodb as UnsafeNativeMethods.ADORecordsetConstruction);
            UnsafeNativeMethods.ADORecordConstruction?   record    = null;

            if (null != recordset)
            {
                if (multipleResults)
                {
                    // The NextRecordset method is not available on a disconnected Recordset object, where ActiveConnection has been set to NULL
                    object activeConnection;
                    activeConnection = ((UnsafeNativeMethods.Recordset15)adodb).get_ActiveConnection();

                    if (null == activeConnection)
                    {
                        multipleResults = false;
                    }
                }
            }
            else
            {
                record = (adodb as UnsafeNativeMethods.ADORecordConstruction);

                if (null != record)
                {
                    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;
                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;
                        OleDbHResult hr = ((UnsafeNativeMethods.Recordset15)adodb).NextRecordset(out recordsAffected, out nextresult);

                        if (0 > hr)
                        {
                            // Current provider does not support returning multiple recordsets from a single execution.
                            if (ODB.ADODB_NextResultError != (int)hr)
                            {
                                SafeNativeMethods.Wrapper.ClearErrorInfo();

                                string message = string.Empty;
                                throw new COMException(message, (int)hr);
                            }
                            break;
                        }
                        adodb = nextresult;
                        if (null != adodb)
                        {
                            recordset = (UnsafeNativeMethods.ADORecordsetConstruction)adodb;

                            if (incrementResultCount)
                            {
                                resultCount++;
                            }
                            continue;
                        }
                    }
                    break;
                } while (null != recordset);

                if ((null != recordset) && (closeRecordset || (null == adodb)))
                {
                    FillClose(true, recordset);
                }
            }
            else if (null != record)
            {
                results = FillFromRecord(data, record, srcTable !);
                if (closeRecordset)
                {
                    FillClose(false, record);
                }
            }
            else
            {
                throw ODB.Fill_NotADODB("adodb");
            }
            return(results);
        }
Ejemplo n.º 58
0
 private void ProcessResults(OleDbHResult hr) {
     Exception e = OleDbConnection.ProcessResults(hr, _parentConnection, this);
     if (null != e) { throw e; }
 }
Ejemplo n.º 59
0
        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));
        }
Ejemplo n.º 60
0
 static internal string NoErrorMessage(OleDbHResult errorcode) {
     return Res.GetString(Res.OleDb_NoErrorMessage, ODB.ELookup(errorcode));
 }