Example #1
0
        internal void GetDataSource(OleDbConnectionString constr, ref DataSourceWrapper datasrcWrapper)
        {
            OleDbHResult result;

            UnsafeNativeMethods.IDataInitializeGetDataSource dangerousIDataInitializeGetDataSource = this.DangerousIDataInitializeGetDataSource;
            bool success = false;

            RuntimeHelpers.PrepareConstrainedRegions();
            try
            {
                base.DangerousAddRef(ref success);
                string actualConnectionString = constr.ActualConnectionString;
                result = dangerousIDataInitializeGetDataSource(base.handle, IntPtr.Zero, 0x17, actualConnectionString, ref ODB.IID_IDBInitialize, ref datasrcWrapper);
            }
            finally
            {
                if (success)
                {
                    base.DangerousRelease();
                }
            }
            if (result < OleDbHResult.S_OK)
            {
                if (OleDbHResult.REGDB_E_CLASSNOTREG == result)
                {
                    throw ODB.ProviderUnavailable(constr.Provider, null);
                }
                throw OleDbConnection.ProcessResults(result, null, null);
            }
            if (datasrcWrapper.IsInvalid)
            {
                SafeNativeMethods.Wrapper.ClearErrorInfo();
                throw ODB.ProviderUnavailable(constr.Provider, null);
            }
        }
Example #2
0
        private static OleDbDataReader GetEnumeratorReader(object?value)
        {
            NativeMethods.ISourcesRowset?srcrowset;

            try
            {
                srcrowset = (NativeMethods.ISourcesRowset?)value;
            }
            catch (InvalidCastException)
            {
                throw ODB.ISourcesRowsetNotSupported();
            }
            if (null == srcrowset)
            {
                throw ODB.ISourcesRowsetNotSupported();
            }

            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);
        }
Example #3
0
        private void ProcessResults(OleDbHResult hr)
        {
            Exception?e = OleDbConnection.ProcessResults(hr, _parentConnection, this);

            if (null != e)
            {
                throw e;
            }
        }
Example #4
0
        private void ProcessResults(OleDbHResult hr)
        {
            Exception exception = OleDbConnection.ProcessResults(hr, this._parentConnection, this);

            if (exception != null)
            {
                throw exception;
            }
        }
Example #5
0
        private void ProcessResultsNoReset(OleDbHResult hr)
        {
            Exception e = OleDbConnection.ProcessResults(hr, null, this);

            if (null != e)
            {
                throw e;
            }
        }
        private void ProcessResultsNoReset(OleDbHResult hr)
        {
            Exception exception = OleDbConnection.ProcessResults(hr, null, this);

            if (exception != null)
            {
                throw exception;
            }
        }
        private void ExecuteCommandTextErrorHandling(OleDbHResult hr)
        {
            Exception e = OleDbConnection.ProcessResults(hr, this._connection, this);

            if (e != null)
            {
                throw this.ExecuteCommandTextSpecialErrorHandling(hr, e);
            }
        }
        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;
            }
        }
Example #9
0
        private void ExecuteCommandTextErrorHandling(OleDbHResult hr)
        {
            Exception e = OleDbConnection.ProcessResults(hr, _connection, this);

            if (null != e)
            {
                e = ExecuteCommandTextSpecialErrorHandling(hr, e);
                throw e;
            }
        }
        private void ProcessResults(OleDbHResult hr)
        {
            OleDbConnection connection = this.Connection;
            Exception       exception  = OleDbConnection.ProcessResults(hr, connection, connection);

            if (exception != null)
            {
                throw exception;
            }
        }
Example #11
0
        internal void GetDataSource(OleDbConnectionString constr, ref DataSourceWrapper datasrcWrapper)
        {
            OleDbHResult hr;

            UnsafeNativeMethods.IDataInitializeGetDataSource GetDataSource = DangerousIDataInitializeGetDataSource !;
            bool mustRelease = false;

            RuntimeHelpers.PrepareConstrainedRegions();
            try
            {
                DangerousAddRef(ref mustRelease);

                // this is the string that DataLinks / OLE DB Services will use to create the provider
                string connectionString = constr.ActualConnectionString !;

                // base.handle is the 'this' pointer for making the COM call to GetDataSource
                // the datasrcWrapper will store the IID_IDBInitialize pointer
                // call IDataInitiailze::GetDataSource via the delegate
                hr = GetDataSource(base.handle, IntPtr.Zero, ODB.CLSCTX_ALL, connectionString, ref ODB.IID_IDBInitialize, ref datasrcWrapper);
            }
            finally
            {
                if (mustRelease)
                {
                    DangerousRelease();
                }
            }
            if (hr < 0)
            { // ignore infomsg
                if (OleDbHResult.REGDB_E_CLASSNOTREG == hr)
                {
                    throw ODB.ProviderUnavailable(constr.Provider, null);
                }
                Exception?e = OleDbConnection.ProcessResults(hr, null, null);
                Debug.Assert(null != e, "CreateProviderError");
                throw e;
            }
            else if (datasrcWrapper.IsInvalid)
            {
                SafeNativeMethods.Wrapper.ClearErrorInfo();
                throw ODB.ProviderUnavailable(constr.Provider, null);
            }
            Debug.Assert(!datasrcWrapper.IsInvalid, "bad DataSource");
        }
Example #12
0
        internal void SetDataSourcePropertyValue(Guid propertySet, int propertyID, string description, bool required, object value)
        {
            CheckStateOpen(ADP.SetProperties);
            OleDbHResult hr;

            using (IDBPropertiesWrapper idbProperties = IDBProperties())
            {
                using (DBPropSet propSet = DBPropSet.CreateProperty(propertySet, propertyID, required, value))
                {
                    hr = idbProperties.Value.SetProperties(propSet.PropertySetCount, propSet);

                    if (hr < 0)
                    {
                        Exception e = OleDbConnection.ProcessResults(hr, null, this);
                        if (OleDbHResult.DB_E_ERRORSOCCURRED == hr)
                        {
                            StringBuilder builder = new StringBuilder();
                            Debug.Assert(1 == propSet.PropertySetCount, "too many PropertySets");

                            tagDBPROP[] dbprops = propSet.GetPropertySet(0, out propertySet);
                            Debug.Assert(1 == dbprops.Length, "too many Properties");

                            ODB.PropsetSetFailure(builder, description, dbprops[0].dwStatus);

                            e = ODB.PropsetSetFailure(builder.ToString(), e);
                        }
                        if (null != e)
                        {
                            throw e;
                        }
                    }
                    else
                    {
                        SafeNativeMethods.Wrapper.ClearErrorInfo();
                    }
                }
            }
        }
        static private 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;

            Bid.Trace("<oledb.ISourcesRowset.GetSourcesRowset|API|OLEDB> IID_IRowset\n");
            OleDbHResult hr = srcrowset.GetSourcesRowset(ADP.PtrZero, ODB.IID_IRowset, propCount, propSets, out value);

            Bid.Trace("<oledb.ISourcesRowset.GetSourcesRowset|API|OLEDB|RET> %08X{HRESULT}\n", hr);

            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);
        }
 internal OleDbConnectionInternal(OleDbConnectionString constr, OleDbConnection connection)
 {
     this.ConnectionString = constr;
     if (constr.PossiblePrompt && !Environment.UserInteractive)
     {
         throw ODB.PossiblePromptNotUserInteractive();
     }
     try
     {
         OleDbServicesWrapper objectPool = GetObjectPool();
         this._datasrcwrp = new DataSourceWrapper();
         objectPool.GetDataSource(constr, ref this._datasrcwrp);
         if (connection != null)
         {
             this._sessionwrp = new SessionWrapper();
             OleDbHResult hresult = this._datasrcwrp.InitializeAndCreateSession(constr, ref this._sessionwrp);
             if ((OleDbHResult.S_OK > hresult) || this._sessionwrp.IsInvalid)
             {
                 throw OleDbConnection.ProcessResults(hresult, null, null);
             }
             OleDbConnection.ProcessResults(hresult, connection, connection);
         }
     }
     catch
     {
         if (this._sessionwrp != null)
         {
             this._sessionwrp.Dispose();
             this._sessionwrp = null;
         }
         if (this._datasrcwrp != null)
         {
             this._datasrcwrp.Dispose();
             this._datasrcwrp = null;
         }
         throw;
     }
 }
Example #15
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);
        }
        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;
            }
        }