Ejemplo n.º 1
0
        public override void Cancel()
        {
            unchecked
            { _changeID++; }

            UnsafeNativeMethods.ICommandText icmdtxt = _icommandText;
            if (null != icmdtxt)
            {
                OleDbHResult hr = OleDbHResult.S_OK;

                lock (icmdtxt)
                {
                    // lock the object to avoid race conditions between using the object and releasing the object
                    // after we acquire the lock, if the class has moved on don't actually call Cancel
                    if (icmdtxt == _icommandText)
                    {
                        hr = icmdtxt.Cancel();
                    }
                }
                if (OleDbHResult.DB_E_CANTCANCEL != hr)
                {
                    // if the provider can't cancel the command - don't cancel the DataReader
                    this.canceling = true;
                }

                // since cancel is allowed to occur at anytime we can't check the connection status
                // since if it returns as closed then the connection will close causing the reader to close
                // and that would introduce the possilbility of one thread reading and one thread closing at the same time
                ProcessResultsNoReset(hr);
            }
            else
            {
                this.canceling = true;
            }
        }
 private void CloseInternalCommand()
 {
     this._changeID++;
     this.commandBehavior = CommandBehavior.Default;
     this._isPrepared     = false;
     UnsafeNativeMethods.ICommandText o = Interlocked.Exchange <UnsafeNativeMethods.ICommandText>(ref this._icommandText, null);
     if (o != null)
     {
         lock (o)
         {
             Marshal.ReleaseComObject(o);
         }
     }
 }
Ejemplo n.º 3
0
        private void CloseInternalCommand()
        {
            unchecked
            { _changeID++; }
            this.commandBehavior = CommandBehavior.Default;
            _isPrepared          = false;

            UnsafeNativeMethods.ICommandText ict = Interlocked.Exchange <UnsafeNativeMethods.ICommandText>(ref _icommandText, null);
            if (null != ict)
            {
                lock (ict)
                {
                    // lock the object to avoid race conditions between using the object and releasing the object
                    Marshal.ReleaseComObject(ict);
                }
            }
        }
Ejemplo n.º 4
0
        private bool PropertiesOnCommand(bool throwNotSupported)
        {
            if (null != _icommandText)
            {
                return(true);
            }
            Debug.Assert(!_isPrepared, "null command isPrepared");

            OleDbConnection connection = _connection;

            if (null == connection)
            {
                connection.CheckStateOpen(ODB.Properties);
            }
            if (!_trackingForClose)
            {
                _trackingForClose = true;
                connection.AddWeakReference(this, OleDbReferenceCollection.CommandTag);
            }
            _icommandText = connection.ICommandText();

            if (null == _icommandText)
            {
                if (throwNotSupported || HasParameters())
                {
                    throw ODB.CommandTextNotSupported(connection.Provider, null);
                }
                return(false);
            }

            using (DBPropSet propSet = CommandPropertySets())
            {
                if (null != propSet)
                {
                    UnsafeNativeMethods.ICommandProperties icommandProperties = ICommandProperties();
                    OleDbHResult hr = icommandProperties.SetProperties(propSet.PropertySetCount, propSet);

                    if (hr < 0)
                    {
                        SafeNativeMethods.Wrapper.ClearErrorInfo();
                    }
                }
            }
            return(true);
        }
 private bool PropertiesOnCommand(bool throwNotSupported)
 {
     if (this._icommandText == null)
     {
         OleDbConnection connection = this._connection;
         if (connection == null)
         {
             connection.CheckStateOpen("Properties");
         }
         if (!this._trackingForClose)
         {
             this._trackingForClose = true;
             connection.AddWeakReference(this, 1);
         }
         this._icommandText = connection.ICommandText();
         if (this._icommandText == null)
         {
             if (throwNotSupported || this.HasParameters())
             {
                 throw ODB.CommandTextNotSupported(connection.Provider, null);
             }
             return(false);
         }
         using (DBPropSet set = this.CommandPropertySets())
         {
             if (set != null)
             {
                 System.Data.Common.UnsafeNativeMethods.ICommandProperties properties = this.ICommandProperties();
                 Bid.Trace("<oledb.ICommandProperties.SetProperties|API|OLEDB> %d#\n", this.ObjectID);
                 OleDbHResult result = properties.SetProperties(set.PropertySetCount, set);
                 Bid.Trace("<oledb.ICommandProperties.SetProperties|API|OLEDB|RET> %08X{HRESULT}\n", result);
                 if (result < OleDbHResult.S_OK)
                 {
                     SafeNativeMethods.Wrapper.ClearErrorInfo();
                 }
             }
         }
     }
     return(true);
 }
        public override void Cancel()
        {
            IntPtr ptr;

            Bid.ScopeEnter(out ptr, "<oledb.OleDbCommand.Cancel|API> %d#\n", this.ObjectID);
            try
            {
                this._changeID++;
                UnsafeNativeMethods.ICommandText text = this._icommandText;
                if (text != null)
                {
                    OleDbHResult result = OleDbHResult.S_OK;
                    lock (text)
                    {
                        if (text == this._icommandText)
                        {
                            Bid.Trace("<oledb.ICommandText.Cancel|API|OLEDB> %d#\n", this.ObjectID);
                            result = text.Cancel();
                            Bid.Trace("<oledb.ICommandText.Cancel|API|OLEDB|RET> %08X{HRESULT}\n", result);
                        }
                    }
                    if (OleDbHResult.DB_E_CANTCANCEL != result)
                    {
                        this.canceling = true;
                    }
                    this.ProcessResultsNoReset(result);
                }
                else
                {
                    this.canceling = true;
                }
            }
            finally
            {
                Bid.ScopeLeave(ref ptr);
            }
        }
Ejemplo n.º 7
0
        private bool PropertiesOnCommand(bool throwNotSupported) {
            if (null != _icommandText) {
                return true;
            }
            Debug.Assert(!_isPrepared, "null command isPrepared");

            OleDbConnection connection = _connection;
            if (null == connection) {
                connection.CheckStateOpen(ODB.Properties);
            }
            if (!_trackingForClose) {
                _trackingForClose = true;
                connection.AddWeakReference(this, OleDbReferenceCollection.CommandTag);
            }
            _icommandText = connection.ICommandText();

            if (null == _icommandText) {
                if (throwNotSupported || HasParameters()) {
                    throw ODB.CommandTextNotSupported(connection.Provider, null);
                }
                return false; // MDAC 57856
            }

            using(DBPropSet propSet = CommandPropertySets()) {
                if (null != propSet) {
                    UnsafeNativeMethods.ICommandProperties icommandProperties = ICommandProperties();

                    Bid.Trace("<oledb.ICommandProperties.SetProperties|API|OLEDB> %d#\n", ObjectID);
                    OleDbHResult hr = icommandProperties.SetProperties(propSet.PropertySetCount, propSet);
                    Bid.Trace("<oledb.ICommandProperties.SetProperties|API|OLEDB|RET> %08X{HRESULT}\n", hr);

                    if (hr < 0) {
                        SafeNativeMethods.Wrapper.ClearErrorInfo();
                    }
                }
            }
            return true;
        }
 private bool PropertiesOnCommand(bool throwNotSupported)
 {
     if (this._icommandText == null)
     {
         OleDbConnection connection = this._connection;
         if (connection == null)
         {
             connection.CheckStateOpen("Properties");
         }
         if (!this._trackingForClose)
         {
             this._trackingForClose = true;
             connection.AddWeakReference(this, 1);
         }
         this._icommandText = connection.ICommandText();
         if (this._icommandText == null)
         {
             if (throwNotSupported || this.HasParameters())
             {
                 throw ODB.CommandTextNotSupported(connection.Provider, null);
             }
             return false;
         }
         using (DBPropSet set = this.CommandPropertySets())
         {
             if (set != null)
             {
                 System.Data.Common.UnsafeNativeMethods.ICommandProperties properties = this.ICommandProperties();
                 Bid.Trace("<oledb.ICommandProperties.SetProperties|API|OLEDB> %d#\n", this.ObjectID);
                 OleDbHResult result = properties.SetProperties(set.PropertySetCount, set);
                 Bid.Trace("<oledb.ICommandProperties.SetProperties|API|OLEDB|RET> %08X{HRESULT}\n", result);
                 if (result < OleDbHResult.S_OK)
                 {
                     SafeNativeMethods.Wrapper.ClearErrorInfo();
                 }
             }
         }
     }
     return true;
 }