Beispiel #1
0
        private int RollbackInternal(bool exceptionHandling)
        {
            int hr = 0;

            if (null != this.localTransaction)
            {
                Marshal.Release(this.iunknown);
                this.iunknown = IntPtr.Zero;

                // there is no recovery if Rollback throws an exception
                UnsafeNativeMethods.ITransactionLocal local = this.localTransaction;
                this.localTransaction = null;

                if (null != this.weakTransaction)
                {
                    OleDbTransaction transaction = (OleDbTransaction)this.weakTransaction.Target;
                    if ((null != transaction) && this.weakTransaction.IsAlive)
                    {
                        hr = transaction.RollbackInternal(exceptionHandling);
                        GC.KeepAlive(transaction);
                        GC.SuppressFinalize(transaction);
                        if (hr < 0)
                        {
                            SafeNativeMethods.ClearErrorInfo();
                            return(hr);
                        }
                    }
                    this.weakTransaction = null;
                }
#if DEBUG
                if (AdapterSwitches.OleDbTrace.TraceInfo)
                {
                    ODB.Trace_Begin("ITransactionLocal", "Abort");
                }
#endif
                hr = local.Abort(0, 0, 0);

#if DEBUG
                if (AdapterSwitches.OleDbTrace.TraceInfo)
                {
                    ODB.Trace_End("ITransactionLocal", "Abort", hr);
                }
#endif
                if (hr < 0)
                {
                    if (exceptionHandling)
                    {
                        ProcessResults(hr);
                    }
                    else
                    {
                        SafeNativeMethods.ClearErrorInfo();
                    }
                }
            }
            return(hr);
        }
        //override protected int Fill(DataTable dataTable, IDataReader dataReader) { // MDAC 65506
        //    return base.Fill(dataTable, dataReader);
        //}

        private int FillFromRecordset(Object data, UnsafeNativeMethods.ADORecordsetConstruction recordset, string srcTable, out bool incrementResultCount)
        {
            incrementResultCount = false;

            IntPtr chapter; /*ODB.DB_NULL_HCHAPTER*/
            object result = null;

            try {
                int hr;
#if DEBUG
                ODB.Trace_Begin("ADORecordsetConstruction", "get_Rowset");
#endif
                hr = recordset.get_Rowset(out result);
#if DEBUG
                ODB.Trace_End("ADORecordsetConstruction", "get_Rowset", hr);
                ODB.Trace_Begin("ADORecordsetConstruction", "get_Chapter");
#endif
                hr = recordset.get_Chapter(out chapter);
#if DEBUG
                ODB.Trace_End("ADORecordsetConstruction", "get_Chapter", hr);
#endif
            }
            catch (Exception e) {
                ADP.TraceException(e);
                throw ODB.Fill_EmptyRecordSet("adodbRecordSet", e);
            }

            if (null != result)
            {
                CommandBehavior behavior = (MissingSchemaAction.AddWithKey != MissingSchemaAction) ? 0 : CommandBehavior.KeyInfo;
                behavior |= CommandBehavior.SequentialAccess;

                try {
                    using (OleDbDataReader dataReader = new OleDbDataReader(null, null, 0, chapter)) {
                        dataReader.InitializeIRowset(result, -1, behavior);
                        dataReader.BuildMetaInfo();

                        incrementResultCount = (0 < dataReader.FieldCount); // MDAC 59632
                        if (incrementResultCount)
                        {
                            if (data is DataTable)
                            {
                                return(base.Fill((DataTable)data, dataReader)); // MDAC 65506
                            }
                            else
                            {
                                return(base.Fill((DataSet)data, srcTable, dataReader, 0, 0));
                            }
                        }
                    }
                }
                catch { // MDAC 80973
                    throw;
                }
            }
            return(0);
        }
Beispiel #3
0
        private void CommitInternal()
        {
            if (null == this.localTransaction)
            {
                return;
            }
            if (null != this.weakTransaction)
            {
                OleDbTransaction transaction = (OleDbTransaction)this.weakTransaction.Target;
                if ((null != transaction) && this.weakTransaction.IsAlive)
                {
                    transaction.CommitInternal();
                }
                this.weakTransaction = null;
            }
#if DEBUG
            if (AdapterSwitches.OleDbTrace.TraceInfo)
            {
                ODB.Trace_Begin("ITransactionLocal", "Commit");
            }
#endif
            int hr;
            hr = this.localTransaction.Commit(0, /*OleDbTransactionControl.SynchronousPhaseTwo*/ 2, 0);

#if DEBUG
            if (AdapterSwitches.OleDbTrace.TraceInfo)
            {
                ODB.Trace_End("ITransactionLocal", "Commit", hr);
            }
#endif
            if (hr < 0)
            {
                if (ODB.XACT_E_NOTRANSACTION == hr)
                {
                    Marshal.Release(this.iunknown);
                    this.iunknown = IntPtr.Zero;

                    this.localTransaction = null;
                    DisposeManaged();
                }
                ProcessResults(hr);
            }

            if (IntPtr.Zero != this.iunknown)
            {
                Marshal.Release(this.iunknown);
                this.iunknown = IntPtr.Zero;
            }

            // if an exception is thrown, user can try to commit their transaction again
            this.localTransaction = null;
            DisposeManaged();
            GC.KeepAlive(this);
            GC.SuppressFinalize(this);
        }
        /// <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
            }
        }
Beispiel #5
0
        internal void BeginInternal(UnsafeNativeMethods.ITransactionLocal transaction, IsolationLevel isolevel)
        {
            switch (isolevel)
            {
            case IsolationLevel.Unspecified:
            case IsolationLevel.Chaos:
            case IsolationLevel.ReadUncommitted:
            case IsolationLevel.ReadCommitted:
            case IsolationLevel.RepeatableRead:
            case IsolationLevel.Serializable:
                break;

            default:
                throw ADP.InvalidIsolationLevel((int)isolationLevel);
            }

            int hr, transactionLevel = 0;

#if DEBUG
            if (AdapterSwitches.OleDbTrace.TraceInfo)
            {
                ODB.Trace_Begin("ITransactionLocal", "StartTransaction", this.isolationLevel.ToString("G"));
            }
#endif
            // $UNDONE: how is it possible to guard against something like ThreadAbortException
            //          when transaction started, but aborted before localTransaction is set
            //          so we know to rollback the transaction for when connection is returned to the pool
            hr = transaction.StartTransaction((int)isolevel, 0, null, out transactionLevel);

#if DEBUG
            if (AdapterSwitches.OleDbTrace.TraceInfo)
            {
                ODB.Trace_End("ITransactionLocal", "StartTransaction", hr, "TransactionLevel=" + transactionLevel);
            }
#endif
            if (hr < 0)
            {
                ProcessResults(hr);
            }

            this.isolationLevel   = isolevel;
            this.localTransaction = transaction;
            this.iunknown         = Marshal.GetIUnknownForObject(transaction);
            GC.KeepAlive(this);
        }
        private int FillFromRecord(Object data, UnsafeNativeMethods.ADORecordConstruction record, string srcTable)
        {
            object result = null;

            try {
                int hr;
#if DEBUG
                ODB.Trace_Begin("ADORecordConstruction", "get_Row");
#endif
                hr = record.get_Row(out result);
#if DEBUG
                ODB.Trace_End("ADORecordConstruction", "get_Row", hr);
#endif
            }
            catch (Exception e) {
                ADP.TraceException(e);
                throw ODB.Fill_EmptyRecord("adodb", e);
            }

            if (null != result)
            {
                CommandBehavior behavior = (MissingSchemaAction.AddWithKey != MissingSchemaAction) ? 0 : CommandBehavior.KeyInfo;

                try {
                    using (OleDbDataReader dataReader = new OleDbDataReader(null, null, 0, IntPtr.Zero)) {
                        dataReader.InitializeIRow(result, -1, behavior | CommandBehavior.SingleRow);
                        dataReader.BuildMetaInfo();

                        if (data is DataTable)
                        {
                            return(base.Fill((DataTable)data, dataReader)); // MDAC 65506
                        }
                        else
                        {
                            return(base.Fill((DataSet)data, srcTable, dataReader, 0, 0));
                        }
                    }
                }
                catch { // MDAC 80973
                    throw;
                }
            }
            return(0);
        }
Beispiel #7
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));
                    }
                }
            }
        }
Beispiel #8
0
        internal OleDbException(UnsafeNativeMethods.IErrorInfo errorInfo, int errorCode, Exception inner) : base("", inner)
        {
            // copy error information into this structure so that it can be serialized by value
            this.oledbErrors = new OleDbErrorCollection((UnsafeNativeMethods.IErrorRecords)errorInfo);

            if (null != errorInfo)
            {
                // message
#if DEBUG
                ODB.Trace_Begin(4, "IErrorInfo", "GetDescription");
#endif
                errorInfo.GetDescription(out this.message);
#if DEBUG
                ODB.Trace_End(4, "IErrorInfo", "GetDescription", 0, this.message);
#endif
                this.message = OleDbErrorCollection.BuildFullMessage(Errors, this.message);
                if (ADP.IsEmpty(this.message))
                {
                    this.message = ODB.NoErrorMessage(errorCode); // MDAC 71170
                }

                // source
#if DEBUG
                ODB.Trace_Begin(4, "IErrorInfo", "GetSource");
#endif
                errorInfo.GetSource(out this.source);
#if DEBUG
                ODB.Trace_End(4, "IErrorInfo", "GetSource", 0, this.source);
#endif
                if (null == this.source)
                {
                    this.source = "";
                }
            }
            HResult = errorCode;
        }
        /// <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);
                }
            }
        }