Esempio 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;
        internal Dictionary <string, OleDbPropertyInfo> GetValues()
        {
            Dictionary <string, OleDbPropertyInfo> dictionary = null;
            bool success = false;

            RuntimeHelpers.PrepareConstrainedRegions();
            try
            {
                base.DangerousAddRef(ref success);
                if (!(ADP.PtrZero != base.handle))
                {
                    return(dictionary);
                }
                dictionary = new Dictionary <string, OleDbPropertyInfo>(StringComparer.OrdinalIgnoreCase);
                IntPtr           handle         = base.handle;
                tagDBPROPINFO    structure      = new tagDBPROPINFO();
                tagDBPROPINFOSET gdbpropinfoset = new tagDBPROPINFOSET();
                int num2 = 0;
                while (num2 < this.setCount)
                {
                    Marshal.PtrToStructure(handle, gdbpropinfoset);
                    int    cPropertyInfos  = gdbpropinfoset.cPropertyInfos;
                    IntPtr rgPropertyInfos = gdbpropinfoset.rgPropertyInfos;
                    int    num             = 0;
                    while (num < cPropertyInfos)
                    {
                        Marshal.PtrToStructure(rgPropertyInfos, structure);
                        OleDbPropertyInfo info = new OleDbPropertyInfo {
                            _propertySet     = gdbpropinfoset.guidPropertySet,
                            _propertyID      = structure.dwPropertyID,
                            _flags           = structure.dwFlags,
                            _vtype           = structure.vtType,
                            _supportedValues = structure.vValue,
                            _description     = structure.pwszDescription,
                            _lowercase       = structure.pwszDescription.ToLower(CultureInfo.InvariantCulture),
                            _type            = FromVtType(structure.vtType)
                        };
                        if (Bid.AdvancedOn)
                        {
                            Bid.Trace("<oledb.struct.OleDbPropertyInfo|INFO|ADV> \n");
                        }
                        dictionary[info._lowercase] = info;
                        num++;
                        rgPropertyInfos = ADP.IntPtrOffset(rgPropertyInfos, ODB.SizeOf_tagDBPROPINFO);
                    }
                    num2++;
                    handle = ADP.IntPtrOffset(handle, ODB.SizeOf_tagDBPROPINFOSET);
                }
            }
            finally
            {
                if (success)
                {
                    base.DangerousRelease();
                }
            }
            return(dictionary);
        }
Esempio n. 3
0
        internal Dictionary <string, OleDbPropertyInfo> GetValues()
        {
            Dictionary <string, OleDbPropertyInfo> propertyLookup = null;

            bool mustRelease = false;

            RuntimeHelpers.PrepareConstrainedRegions();
            try {
                DangerousAddRef(ref mustRelease);
                if (ADP.PtrZero != this.handle)
                {
                    propertyLookup = new Dictionary <string, OleDbPropertyInfo>(StringComparer.OrdinalIgnoreCase);

                    IntPtr           setPtr      = this.handle;
                    tagDBPROPINFO    propinfo    = new tagDBPROPINFO();
                    tagDBPROPINFOSET propinfoset = new tagDBPROPINFOSET();

                    for (int i = 0; i < setCount; ++i, setPtr = ADP.IntPtrOffset(setPtr, ODB.SizeOf_tagDBPROPINFOSET))
                    {
                        Marshal.PtrToStructure(setPtr, propinfoset);

                        int    infoCount = propinfoset.cPropertyInfos;
                        IntPtr infoPtr   = propinfoset.rgPropertyInfos;
                        for (int k = 0; k < infoCount; ++k, infoPtr = ADP.IntPtrOffset(infoPtr, ODB.SizeOf_tagDBPROPINFO))
                        {
                            Marshal.PtrToStructure(infoPtr, propinfo);

                            OleDbPropertyInfo propertyInfo = new OleDbPropertyInfo();
                            propertyInfo._propertySet     = propinfoset.guidPropertySet;
                            propertyInfo._propertyID      = propinfo.dwPropertyID;
                            propertyInfo._flags           = propinfo.dwFlags;
                            propertyInfo._vtype           = propinfo.vtType;
                            propertyInfo._supportedValues = propinfo.vValue;
                            propertyInfo._description     = propinfo.pwszDescription;
                            propertyInfo._lowercase       = propinfo.pwszDescription.ToLower(CultureInfo.InvariantCulture);
                            propertyInfo._type            = PropertyInfoSet.FromVtType(propinfo.vtType);

                            if (Bid.AdvancedOn)
                            {
                                Bid.Trace("<oledb.struct.OleDbPropertyInfo|INFO|ADV> \n");//, propertyInfo);
                            }
                            propertyLookup[propertyInfo._lowercase] = propertyInfo;
                        }
                    }
                }
            }
            finally {
                if (mustRelease)
                {
                    DangerousRelease();
                }
            }
            return(propertyLookup);
        }
Esempio n. 4
0
        public override object this[string keyword] {
            get {
                ADP.CheckArgumentNull(keyword, "keyword");
                object   value;
                Keywords index;
                if (_keywords.TryGetValue(keyword, out index))
                {
                    value = GetAt(index);
                }
                else if (!base.TryGetValue(keyword, out value))
                {
                    Dictionary <string, OleDbPropertyInfo> dynamic = GetProviderInfo(Provider);
                    OleDbPropertyInfo info = dynamic[keyword];
                    value = info._defaultValue;
                }
                return(value);
            }
            set {
                if (null != value)
                {
                    ADP.CheckArgumentNull(keyword, "keyword");
                    Keywords index;
                    if (_keywords.TryGetValue(keyword, out index))
                    {
                        switch (index)
                        {
                        case Keywords.DataSource:          DataSource = ConvertToString(value); break;

                        case Keywords.FileName:            FileName = ConvertToString(value); break;

//                      case Keywords.NamedConnection:     NamedConnection = ConvertToString(value); break;
                        case Keywords.Provider:            Provider = ConvertToString(value); break;

                        case Keywords.OleDbServices:       OleDbServices = ConvertToInt32(value); break;

                        case Keywords.PersistSecurityInfo: PersistSecurityInfo = ConvertToBoolean(value); break;

                        default:
                            Debug.Assert(false, "unexpected keyword");
                            throw ADP.KeywordNotSupported(keyword);
                        }
                    }
                    else
                    {
                        base[keyword] = value;
                        ClearPropertyDescriptors();
                    }
                }
                else
                {
                    Remove(keyword);
                }
            }
        }
Esempio n. 5
0
        internal Dictionary<string,OleDbPropertyInfo> GetValues() {
            Dictionary<string,OleDbPropertyInfo> propertyLookup = null;
            
            bool mustRelease = false;            
            RuntimeHelpers.PrepareConstrainedRegions();
            try {
                DangerousAddRef(ref mustRelease);
                if (ADP.PtrZero != this.handle) {
                    propertyLookup = new Dictionary<string,OleDbPropertyInfo>(StringComparer.OrdinalIgnoreCase);

                    IntPtr setPtr = this.handle;
                    tagDBPROPINFO propinfo = new tagDBPROPINFO();
                    tagDBPROPINFOSET propinfoset = new tagDBPROPINFOSET();

                    for (int i = 0; i < setCount; ++i, setPtr = ADP.IntPtrOffset(setPtr, ODB.SizeOf_tagDBPROPINFOSET)) {
                        Marshal.PtrToStructure(setPtr, propinfoset);

                        int infoCount = propinfoset.cPropertyInfos;
                        IntPtr infoPtr = propinfoset.rgPropertyInfos;
                        for(int k = 0; k < infoCount; ++k, infoPtr = ADP.IntPtrOffset(infoPtr, ODB.SizeOf_tagDBPROPINFO)) {
                            Marshal.PtrToStructure(infoPtr, propinfo);

                            OleDbPropertyInfo propertyInfo = new OleDbPropertyInfo();
                            propertyInfo._propertySet = propinfoset.guidPropertySet;
                            propertyInfo._propertyID = propinfo.dwPropertyID;
                            propertyInfo._flags = propinfo.dwFlags;
                            propertyInfo._vtype = propinfo.vtType;
                            propertyInfo._supportedValues = propinfo.vValue;
                            propertyInfo._description = propinfo.pwszDescription;
                            propertyInfo._lowercase = propinfo.pwszDescription.ToLower(CultureInfo.InvariantCulture);
                            propertyInfo._type = PropertyInfoSet.FromVtType(propinfo.vtType);

                            if (Bid.AdvancedOn) {
                                Bid.Trace("<oledb.struct.OleDbPropertyInfo|INFO|ADV> \n");//, propertyInfo);
                            }
                            propertyLookup[propertyInfo._lowercase] = propertyInfo;
                        }
                    }
                }
            }
            finally {
                if (mustRelease) {
                    DangerousRelease();
                }
            }
            return propertyLookup;
        }
Esempio n. 6
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);
        }
        public override object this[string keyword]
        {
            get
            {
                object   obj2;
                Keywords keywords;
                Bid.Trace("<comm.OleDbConnectionStringBuilder.get_Item|API> keyword='%ls'\n", keyword);
                ADP.CheckArgumentNull(keyword, "keyword");
                if (_keywords.TryGetValue(keyword, out keywords))
                {
                    return(this.GetAt(keywords));
                }
                if (!base.TryGetValue(keyword, out obj2))
                {
                    OleDbPropertyInfo info = this.GetProviderInfo(this.Provider)[keyword];
                    obj2 = info._defaultValue;
                }
                return(obj2);
            }
            set
            {
                Bid.Trace("<comm.OleDbConnectionStringBuilder.set_Item|API> keyword='%ls'\n", keyword);
                if (value != null)
                {
                    Keywords keywords2;
                    ADP.CheckArgumentNull(keyword, "keyword");
                    if (_keywords.TryGetValue(keyword, out keywords2))
                    {
                        switch (keywords2)
                        {
                        case Keywords.FileName:
                            this.FileName = ConvertToString(value);
                            return;

                        case Keywords.Provider:
                            this.Provider = ConvertToString(value);
                            return;

                        case Keywords.DataSource:
                            this.DataSource = ConvertToString(value);
                            return;

                        case Keywords.PersistSecurityInfo:
                            this.PersistSecurityInfo = ConvertToBoolean(value);
                            return;

                        case Keywords.OleDbServices:
                            this.OleDbServices = ConvertToInt32(value);
                            return;
                        }
                        throw ADP.KeywordNotSupported(keyword);
                    }
                    base[keyword] = value;
                    this.ClearPropertyDescriptors();
                }
                else
                {
                    this.Remove(keyword);
                }
            }
        }
        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);
        }
 internal Dictionary<string, OleDbPropertyInfo> GetValues()
 {
     Dictionary<string, OleDbPropertyInfo> dictionary = null;
     bool success = false;
     RuntimeHelpers.PrepareConstrainedRegions();
     try
     {
         base.DangerousAddRef(ref success);
         if (!(ADP.PtrZero != base.handle))
         {
             return dictionary;
         }
         dictionary = new Dictionary<string, OleDbPropertyInfo>(StringComparer.OrdinalIgnoreCase);
         IntPtr handle = base.handle;
         tagDBPROPINFO structure = new tagDBPROPINFO();
         tagDBPROPINFOSET gdbpropinfoset = new tagDBPROPINFOSET();
         int num2 = 0;
         while (num2 < this.setCount)
         {
             Marshal.PtrToStructure(handle, gdbpropinfoset);
             int cPropertyInfos = gdbpropinfoset.cPropertyInfos;
             IntPtr rgPropertyInfos = gdbpropinfoset.rgPropertyInfos;
             int num = 0;
             while (num < cPropertyInfos)
             {
                 Marshal.PtrToStructure(rgPropertyInfos, structure);
                 OleDbPropertyInfo info = new OleDbPropertyInfo {
                     _propertySet = gdbpropinfoset.guidPropertySet,
                     _propertyID = structure.dwPropertyID,
                     _flags = structure.dwFlags,
                     _vtype = structure.vtType,
                     _supportedValues = structure.vValue,
                     _description = structure.pwszDescription,
                     _lowercase = structure.pwszDescription.ToLower(CultureInfo.InvariantCulture),
                     _type = FromVtType(structure.vtType)
                 };
                 if (Bid.AdvancedOn)
                 {
                     Bid.Trace("<oledb.struct.OleDbPropertyInfo|INFO|ADV> \n");
                 }
                 dictionary[info._lowercase] = info;
                 num++;
                 rgPropertyInfos = ADP.IntPtrOffset(rgPropertyInfos, ODB.SizeOf_tagDBPROPINFO);
             }
             num2++;
             handle = ADP.IntPtrOffset(handle, ODB.SizeOf_tagDBPROPINFOSET);
         }
     }
     finally
     {
         if (success)
         {
             base.DangerousRelease();
         }
     }
     return dictionary;
 }