Ejemplo n.º 1
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, 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;
Ejemplo n.º 2
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> 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;
        }
        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;
 }