コード例 #1
0
        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);
        }
コード例 #2
0
 internal object GetPropertyValue(Guid propertySet, int propertyID)
 {
     tagDBPROP[] gdbpropArray;
     if (this._icommandText == null)
     {
         return(OleDbPropertyStatus.NotSupported);
     }
     System.Data.Common.UnsafeNativeMethods.ICommandProperties properties = this.ICommandProperties();
     using (PropertyIDSet set2 = new PropertyIDSet(propertySet, propertyID))
     {
         OleDbHResult result;
         using (DBPropSet set = new DBPropSet(properties, 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);
 }
コード例 #3
0
 internal PropertyInfoSet(UnsafeNativeMethods.IDBProperties idbProperties, PropertyIDSet propIDSet) : base(IntPtr.Zero, true) {
     OleDbHResult hr;
     int propIDSetCount = propIDSet.Count; // avoid need for ReliabilityContract on get_Count
     Bid.Trace("<oledb.IDBProperties.GetPropertyInfo|API|OLEDB>\n");
     RuntimeHelpers.PrepareConstrainedRegions();
     try {} finally {
         hr = idbProperties.GetPropertyInfo(propIDSetCount, propIDSet, out this.setCount, out base.handle, out this.descBuffer);
     }
     Bid.Trace("<oledb.IDBProperties.GetPropertyInfo|API|OLEDB|RET> %08X{HRESULT}\n", hr);
     if ((0 <= hr) && (ADP.PtrZero != handle)) {
         SafeNativeMethods.Wrapper.ClearErrorInfo();
     }
 }
コード例 #4
0
 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);
     }
 }
コード例 #5
0
ファイル: DBPropSet.cs プロジェクト: uQr/referencesource
        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);
            }
        }
コード例 #6
0
        internal PropertyInfoSet(UnsafeNativeMethods.IDBProperties idbProperties, PropertyIDSet propIDSet) : base(IntPtr.Zero, true)
        {
            OleDbHResult hr;
            int          propIDSetCount = propIDSet.Count; // avoid need for ReliabilityContract on get_Count

            Bid.Trace("<oledb.IDBProperties.GetPropertyInfo|API|OLEDB>\n");
            RuntimeHelpers.PrepareConstrainedRegions();
            try {} finally {
                hr = idbProperties.GetPropertyInfo(propIDSetCount, propIDSet, out this.setCount, out base.handle, out this.descBuffer);
            }
            Bid.Trace("<oledb.IDBProperties.GetPropertyInfo|API|OLEDB|RET> %08X{HRESULT}\n", hr);
            if ((0 <= hr) && (ADP.PtrZero != handle))
            {
                SafeNativeMethods.Wrapper.ClearErrorInfo();
            }
        }
コード例 #7
0
        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);
            }
        }
コード例 #8
0
        internal PropertyInfoSet(UnsafeNativeMethods.IDBProperties idbProperties, PropertyIDSet propIDSet) : base(IntPtr.Zero, true)
        {
            OleDbHResult hr;
            int          propIDSetCount = propIDSet.Count;

            RuntimeHelpers.PrepareConstrainedRegions();
            try
            { }
            finally
            {
                hr = idbProperties.GetPropertyInfo(propIDSetCount, propIDSet, out this.setCount, out base.handle, out this.descBuffer);
            }
            if ((0 <= hr) && (ADP.PtrZero != handle))
            {
                SafeNativeMethods.Wrapper.ClearErrorInfo();
            }
        }
コード例 #9
0
ファイル: DbPropSet.cs プロジェクト: spydacarnage/corefx
        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);
            }
        }
コード例 #10
0
        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());
                    }
                }
            }
        }
コード例 #11
0
 internal PropertyInfoSet(UnsafeNativeMethods.IDBProperties idbProperties, PropertyIDSet propIDSet) : base(IntPtr.Zero, true)
 {
     OleDbHResult result;
     int count = propIDSet.Count;
     Bid.Trace("<oledb.IDBProperties.GetPropertyInfo|API|OLEDB>\n");
     RuntimeHelpers.PrepareConstrainedRegions();
     try
     {
     }
     finally
     {
         result = idbProperties.GetPropertyInfo(count, propIDSet, out this.setCount, out this.handle, out this.descBuffer);
     }
     Bid.Trace("<oledb.IDBProperties.GetPropertyInfo|API|OLEDB|RET> %08X{HRESULT}\n", result);
     if ((OleDbHResult.S_OK <= result) && (ADP.PtrZero != base.handle))
     {
         SafeNativeMethods.Wrapper.ClearErrorInfo();
     }
 }
コード例 #12
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);
        }
コード例 #13
0
        internal PropertyInfoSet(UnsafeNativeMethods.IDBProperties idbProperties, PropertyIDSet propIDSet) : base(IntPtr.Zero, true)
        {
            OleDbHResult result;
            int          count = propIDSet.Count;

            Bid.Trace("<oledb.IDBProperties.GetPropertyInfo|API|OLEDB>\n");
            RuntimeHelpers.PrepareConstrainedRegions();
            try
            {
            }
            finally
            {
                result = idbProperties.GetPropertyInfo(count, propIDSet, out this.setCount, out this.handle, out this.descBuffer);
            }
            Bid.Trace("<oledb.IDBProperties.GetPropertyInfo|API|OLEDB|RET> %08X{HRESULT}\n", result);
            if ((OleDbHResult.S_OK <= result) && (ADP.PtrZero != base.handle))
            {
                SafeNativeMethods.Wrapper.ClearErrorInfo();
            }
        }
コード例 #14
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);
        }
コード例 #15
0
        internal DBPropSet(UnsafeNativeMethods.IRowsetInfo properties, PropertyIDSet propidset, out OleDbHResult hr) : this()
        {
            Debug.Assert(null != properties, "null IRowsetInfo");

            int propidsetcount = 0;

            if (null != propidset)
            {
                propidsetcount = propidset.Count;
            }
            Bid.Trace("<oledb.IRowsetInfo.GetProperties|API|OLEDB>\n");
            hr = properties.GetProperties(propidsetcount, propidset, out this.propertySetCount, out base.handle);
            Bid.Trace("<oledb.IRowsetInfo.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);
            }
        }
コード例 #16
0
 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);
 }
コード例 #17
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);
        }
コード例 #18
0
        internal object GetPropertyValue(Guid propertySet, int propertyID) {
            if (null != _icommandText) {
                OleDbHResult hr;
                tagDBPROP[] dbprops;
                UnsafeNativeMethods.ICommandProperties icommandProperties = ICommandProperties();

                using(PropertyIDSet propidset = new PropertyIDSet(propertySet, propertyID)) {

                    using(DBPropSet propset = new DBPropSet(icommandProperties, propidset, out hr)) {
                        if (hr < 0) {
                            // VSDD 621427: OLEDB Data Reader masks provider specific errors by raising "Internal .Net Framework 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;
            }
            return OleDbPropertyStatus.NotSupported;
        }
コード例 #19
0
 internal object GetPropertyValue(Guid propertySet, int propertyID)
 {
     tagDBPROP[] gdbpropArray;
     if (this._icommandText == null)
     {
         return OleDbPropertyStatus.NotSupported;
     }
     System.Data.Common.UnsafeNativeMethods.ICommandProperties properties = this.ICommandProperties();
     using (PropertyIDSet set2 = new PropertyIDSet(propertySet, propertyID))
     {
         OleDbHResult result;
         using (DBPropSet set = new DBPropSet(properties, 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;
 }
        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);
        }
 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;
 }
コード例 #22
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);
                        constr.CreatePermissionSet().Demand();

                        // 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 (!_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)) {
                                        // VSDD 671375: 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(Int32) == info._type) {
                                                                    info._defaultValue = 0;
                                                                }
                                                                else if (typeof(Boolean) == 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;
        }
コード例 #23
0
 private object GetPropertyOnRowset(Guid propertySet, int propertyID)
 {
     tagDBPROP[] gdbpropArray;
     System.Data.Common.UnsafeNativeMethods.IRowsetInfo properties = this.IRowsetInfo();
     using (PropertyIDSet set2 = new PropertyIDSet(propertySet, propertyID))
     {
         OleDbHResult result;
         using (DBPropSet set = new DBPropSet(properties, 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;
 }
コード例 #24
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;
        }