Пример #1
0
 internal void SetDataSourcePropertyValue(Guid propertySet, int propertyID, string description, bool required, object value)
 {
     this.CheckStateOpen("SetProperties");
     using (IDBPropertiesWrapper wrapper = this.IDBProperties())
     {
         using (DBPropSet set = DBPropSet.CreateProperty(propertySet, propertyID, required, value))
         {
             Bid.Trace("<oledb.IDBProperties.SetProperties|API|OLEDB> %d#\n", this.ObjectID);
             OleDbHResult result = wrapper.Value.SetProperties(set.PropertySetCount, set);
             Bid.Trace("<oledb.IDBProperties.SetProperties|API|OLEDB|RET> %08X{HRESULT}\n", result);
             if (result < OleDbHResult.S_OK)
             {
                 Exception inner = ProcessResults(result, null, this);
                 if (OleDbHResult.DB_E_ERRORSOCCURRED == result)
                 {
                     StringBuilder builder      = new StringBuilder();
                     tagDBPROP[]   gdbpropArray = set.GetPropertySet(0, out propertySet);
                     ODB.PropsetSetFailure(builder, description, gdbpropArray[0].dwStatus);
                     inner = ODB.PropsetSetFailure(builder.ToString(), inner);
                 }
                 if (inner != null)
                 {
                     throw inner;
                 }
             }
             else
             {
                 SafeNativeMethods.Wrapper.ClearErrorInfo();
             }
         }
     }
 }
        internal object GetDataSourcePropertyValue(Guid propertySet, int propertyID)
        {
            OleDbHResult hr;

            tagDBPROP[] dbprops;
            using (IDBPropertiesWrapper idbProperties = IDBProperties())
            {
                using (PropertyIDSet propidset = new PropertyIDSet(propertySet, propertyID))
                {
                    using (DBPropSet propset = new DBPropSet(idbProperties.Value, propidset, out hr))
                    {
                        if (hr < 0)
                        {
                            // OLEDB Data Reader masks provider specific errors by raising "Internal Data Provider error 30."
                            // DBPropSet c-tor will register the exception and it will be raised at GetPropertySet call in case of failure
                            SafeNativeMethods.Wrapper.ClearErrorInfo();
                        }
                        dbprops = propset.GetPropertySet(0, out propertySet);
                    }
                }
            }
            if (OleDbPropertyStatus.Ok == dbprops[0].dwStatus)
            {
                return(dbprops[0].vValue);
            }
            return(dbprops[0].dwStatus);
        }
Пример #3
0
        internal Dictionary <string, OleDbPropertyInfo> GetPropertyInfo(Guid[] propertySets)
        {
            bool isopen = HasSession;
            OleDbConnectionString constr = ConnectionString;
            Dictionary <string, OleDbPropertyInfo> properties = null;

            if (null == propertySets)
            {
                propertySets = new Guid[0];
            }
            using (PropertyIDSet propidset = new PropertyIDSet(propertySets)) {
                using (IDBPropertiesWrapper idbProperties = IDBProperties()) {
                    using (PropertyInfoSet infoset = new PropertyInfoSet(idbProperties.Value, propidset)) {
                        properties = infoset.GetValues();
                    }
                }
            }
            return(properties);
        }
        internal Dictionary <string, OleDbPropertyInfo> GetPropertyInfo(Guid[] propertySets)
        {
            bool hasSession = this.HasSession;

            if (propertySets == null)
            {
                propertySets = new Guid[0];
            }
            using (PropertyIDSet set2 = new PropertyIDSet(propertySets))
            {
                using (IDBPropertiesWrapper wrapper = this.IDBProperties())
                {
                    using (PropertyInfoSet set = new PropertyInfoSet(wrapper.Value, set2))
                    {
                        return(set.GetValues());
                    }
                }
            }
        }
Пример #5
0
        internal Dictionary <string, OleDbPropertyInfo>?GetPropertyInfo(Guid[] propertySets)
        {
            Dictionary <string, OleDbPropertyInfo>?properties = null;

            if (null == propertySets)
            {
                propertySets = Array.Empty <Guid>();
            }
            using (PropertyIDSet propidset = new PropertyIDSet(propertySets))
            {
                using (IDBPropertiesWrapper idbProperties = IDBProperties())
                {
                    using (PropertyInfoSet infoset = new PropertyInfoSet(idbProperties.Value, propidset))
                    {
                        properties = infoset.GetValues();
                    }
                }
            }
            return(properties);
        }
Пример #6
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();
                    }
                }
            }
        }
 internal object GetDataSourcePropertyValue(Guid propertySet, int propertyID)
 {
     tagDBPROP[] gdbpropArray;
     using (IDBPropertiesWrapper wrapper = this.IDBProperties())
     {
         using (PropertyIDSet set2 = new PropertyIDSet(propertySet, propertyID))
         {
             OleDbHResult result;
             using (DBPropSet set = new DBPropSet(wrapper.Value, set2, out result))
             {
                 if (result < OleDbHResult.S_OK)
                 {
                     SafeNativeMethods.Wrapper.ClearErrorInfo();
                 }
                 gdbpropArray = set.GetPropertySet(0, out propertySet);
             }
         }
     }
     if (gdbpropArray[0].dwStatus == OleDbPropertyStatus.Ok)
     {
         return(gdbpropArray[0].vValue);
     }
     return(gdbpropArray[0].dwStatus);
 }
Пример #8
0
        private Dictionary <string, OleDbPropertyInfo> GetProviderInfo(string provider)
        {
            Dictionary <string, OleDbPropertyInfo> providerInfo = _propertyInfo;

            if (null == providerInfo)
            {
                providerInfo = new Dictionary <string, OleDbPropertyInfo>(StringComparer.OrdinalIgnoreCase);
                if (!ADP.IsEmpty(provider))
                {
                    Dictionary <string, OleDbPropertyInfo> hash = null;
                    try
                    {
                        StringBuilder builder = new StringBuilder();
                        AppendKeyValuePair(builder, DbConnectionStringKeywords.Provider, provider);
                        OleDbConnectionString constr = new OleDbConnectionString(builder.ToString(), true);

                        // load provider without calling Initialize or CreateDataSource
                        using (OleDbConnectionInternal connection = new OleDbConnectionInternal(constr, (OleDbConnection)null))
                        {
                            // get all the init property information for the provider
                            hash = connection.GetPropertyInfo(new Guid[] { OleDbPropertySetGuid.DBInitAll });
                            foreach (KeyValuePair <string, OleDbPropertyInfo> entry in hash)
                            {
                                Keywords          index;
                                OleDbPropertyInfo info = entry.Value;
                                if (!s_keywords.TryGetValue(info._description, out index))
                                {
                                    if ((OleDbPropertySetGuid.DBInit == info._propertySet) &&
                                        ((ODB.DBPROP_INIT_ASYNCH == info._propertyID) ||
                                         (ODB.DBPROP_INIT_HWND == info._propertyID) ||
                                         (ODB.DBPROP_INIT_PROMPT == info._propertyID)))
                                    {
                                        continue; // skip this keyword
                                    }
                                    providerInfo[info._description] = info;
                                }
                            }

                            // what are the unique propertysets?
                            List <Guid> listPropertySets = new List <Guid>();
                            foreach (KeyValuePair <string, OleDbPropertyInfo> entry in hash)
                            {
                                OleDbPropertyInfo info = entry.Value;
                                if (!listPropertySets.Contains(info._propertySet))
                                {
                                    listPropertySets.Add(info._propertySet);
                                }
                            }
                            Guid[] arrayPropertySets = new Guid[listPropertySets.Count];
                            listPropertySets.CopyTo(arrayPropertySets, 0);

                            // get all the init property values for the provider
                            using (PropertyIDSet propidset = new PropertyIDSet(arrayPropertySets))
                            {
                                using (IDBPropertiesWrapper idbProperties = connection.IDBProperties())
                                {
                                    OleDbHResult hr;
                                    using (DBPropSet propset = new DBPropSet(idbProperties.Value, propidset, out hr))
                                    {
                                        // OleDbConnectionStringBuilder is ignoring/hiding potential errors of OLEDB provider when reading its properties information
                                        if (0 <= (int)hr)
                                        {
                                            int count = propset.PropertySetCount;
                                            for (int i = 0; i < count; ++i)
                                            {
                                                Guid        propertyset;
                                                tagDBPROP[] props = propset.GetPropertySet(i, out propertyset);

                                                // attach the default property value to the property info
                                                foreach (tagDBPROP prop in props)
                                                {
                                                    foreach (KeyValuePair <string, OleDbPropertyInfo> entry in hash)
                                                    {
                                                        OleDbPropertyInfo info = entry.Value;
                                                        if ((info._propertyID == prop.dwPropertyID) && (info._propertySet == propertyset))
                                                        {
                                                            info._defaultValue = prop.vValue;

                                                            if (null == info._defaultValue)
                                                            {
                                                                if (typeof(string) == info._type)
                                                                {
                                                                    info._defaultValue = "";
                                                                }
                                                                else if (typeof(int) == info._type)
                                                                {
                                                                    info._defaultValue = 0;
                                                                }
                                                                else if (typeof(bool) == info._type)
                                                                {
                                                                    info._defaultValue = false;
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    catch (System.InvalidOperationException e)
                    {
                        ADP.TraceExceptionWithoutRethrow(e);
                    }
                    catch (System.Data.OleDb.OleDbException e)
                    {
                        ADP.TraceExceptionWithoutRethrow(e);
                    }
                    catch (System.Security.SecurityException e)
                    {
                        ADP.TraceExceptionWithoutRethrow(e);
                    }
                }
                _propertyInfo = providerInfo;
            }
            return(providerInfo);
        }
        private Dictionary <string, OleDbPropertyInfo> GetProviderInfo(string provider)
        {
            Dictionary <string, OleDbPropertyInfo> dictionary = this._propertyInfo;

            if (dictionary == null)
            {
                dictionary = new Dictionary <string, OleDbPropertyInfo>(StringComparer.OrdinalIgnoreCase);
                if (!ADP.IsEmpty(provider))
                {
                    Dictionary <string, OleDbPropertyInfo> propertyInfo = null;
                    try
                    {
                        StringBuilder builder = new StringBuilder();
                        DbConnectionStringBuilder.AppendKeyValuePair(builder, "Provider", provider);
                        OleDbConnectionString constr = new OleDbConnectionString(builder.ToString(), true);
                        constr.CreatePermissionSet().Demand();
                        using (OleDbConnectionInternal internal2 = new OleDbConnectionInternal(constr, null))
                        {
                            Guid[] propertySets = new Guid[] { OleDbPropertySetGuid.DBInitAll };
                            propertyInfo = internal2.GetPropertyInfo(propertySets);
                            foreach (KeyValuePair <string, OleDbPropertyInfo> pair3 in propertyInfo)
                            {
                                Keywords          keywords;
                                OleDbPropertyInfo info2 = pair3.Value;
                                if (!_keywords.TryGetValue(info2._description, out keywords) && ((OleDbPropertySetGuid.DBInit != info2._propertySet) || (((200 != info2._propertyID) && (60 != info2._propertyID)) && (0x40 != info2._propertyID))))
                                {
                                    dictionary[info2._description] = info2;
                                }
                            }
                            List <Guid> list = new List <Guid>();
                            foreach (KeyValuePair <string, OleDbPropertyInfo> pair2 in propertyInfo)
                            {
                                OleDbPropertyInfo info3 = pair2.Value;
                                if (!list.Contains(info3._propertySet))
                                {
                                    list.Add(info3._propertySet);
                                }
                            }
                            Guid[] array = new Guid[list.Count];
                            list.CopyTo(array, 0);
                            using (PropertyIDSet set2 = new PropertyIDSet(array))
                            {
                                using (IDBPropertiesWrapper wrapper = internal2.IDBProperties())
                                {
                                    OleDbHResult result;
                                    using (DBPropSet set = new DBPropSet(wrapper.Value, set2, out result))
                                    {
                                        if (OleDbHResult.S_OK <= result)
                                        {
                                            int propertySetCount = set.PropertySetCount;
                                            for (int i = 0; i < propertySetCount; i++)
                                            {
                                                Guid guid;
                                                foreach (tagDBPROP gdbprop in set.GetPropertySet(i, out guid))
                                                {
                                                    foreach (KeyValuePair <string, OleDbPropertyInfo> pair in propertyInfo)
                                                    {
                                                        OleDbPropertyInfo info = pair.Value;
                                                        if ((info._propertyID == gdbprop.dwPropertyID) && (info._propertySet == guid))
                                                        {
                                                            info._defaultValue = gdbprop.vValue;
                                                            if (info._defaultValue == null)
                                                            {
                                                                if (typeof(string) == info._type)
                                                                {
                                                                    info._defaultValue = "";
                                                                }
                                                                else if (typeof(int) == info._type)
                                                                {
                                                                    info._defaultValue = 0;
                                                                }
                                                                else if (typeof(bool) == info._type)
                                                                {
                                                                    info._defaultValue = false;
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    catch (InvalidOperationException exception3)
                    {
                        ADP.TraceExceptionWithoutRethrow(exception3);
                    }
                    catch (OleDbException exception2)
                    {
                        ADP.TraceExceptionWithoutRethrow(exception2);
                    }
                    catch (SecurityException exception)
                    {
                        ADP.TraceExceptionWithoutRethrow(exception);
                    }
                }
                this._propertyInfo = dictionary;
            }
            return(dictionary);
        }