internal void SetDataSourcePropertyValue(Guid propertySet, int propertyID, string description, bool required, object value) { this.CheckStateOpen("SetProperties"); using (IDBPropertiesWrapper wrapper = this.IDBProperties()) { using (DBPropSet set = DBPropSet.CreateProperty(propertySet, propertyID, required, value)) { Bid.Trace("<oledb.IDBProperties.SetProperties|API|OLEDB> %d#\n", this.ObjectID); OleDbHResult result = wrapper.Value.SetProperties(set.PropertySetCount, set); Bid.Trace("<oledb.IDBProperties.SetProperties|API|OLEDB|RET> %08X{HRESULT}\n", result); if (result < OleDbHResult.S_OK) { Exception inner = ProcessResults(result, null, this); if (OleDbHResult.DB_E_ERRORSOCCURRED == result) { StringBuilder builder = new StringBuilder(); tagDBPROP[] gdbpropArray = set.GetPropertySet(0, out propertySet); ODB.PropsetSetFailure(builder, description, gdbpropArray[0].dwStatus); inner = ODB.PropsetSetFailure(builder.ToString(), inner); } if (inner != null) { throw inner; } } else { SafeNativeMethods.Wrapper.ClearErrorInfo(); } } } }
private DBPropSet CommandPropertySets() { DBPropSet propSet = null; bool keyInfo = (0 != (CommandBehavior.KeyInfo & this.commandBehavior)); // always set the CommandTimeout value? int count = (_executeQuery ? (keyInfo ? 4 : 2) : 1); if (0 < count) { propSet = new DBPropSet(1); tagDBPROP[] dbprops = new tagDBPROP[count]; dbprops[0] = new tagDBPROP(ODB.DBPROP_COMMANDTIMEOUT, false, CommandTimeout); if (_executeQuery) { // 'Microsoft.Jet.OLEDB.4.0' default is DBPROPVAL_AO_SEQUENTIAL dbprops[1] = new tagDBPROP(ODB.DBPROP_ACCESSORDER, false, ODB.DBPROPVAL_AO_RANDOM); if (keyInfo) { // 'Unique Rows' property required for SQLOLEDB to retrieve things like 'BaseTableName' dbprops[2] = new tagDBPROP(ODB.DBPROP_UNIQUEROWS, false, keyInfo); // otherwise 'Microsoft.Jet.OLEDB.4.0' doesn't support IColumnsRowset dbprops[3] = new tagDBPROP(ODB.DBPROP_IColumnsRowset, false, true); } } propSet.SetPropertySet(0, OleDbPropertySetGuid.Rowset, dbprops); } return(propSet); }
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); }
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); }
internal static DBPropSet CreateProperty(Guid propertySet, int propertyId, bool required, object value) { tagDBPROP gdbprop = new tagDBPROP(propertyId, required, value); DBPropSet set = new DBPropSet(1); set.SetPropertySet(0, propertySet, new tagDBPROP[] { gdbprop }); return(set); }
static internal DBPropSet CreateProperty(Guid propertySet, int propertyId, object value) { DBPropSet propertyset = new DBPropSet(); propertyset.PropertySetCount = 1; propertyset.WritePropertySet(propertySet, 1); propertyset.WriteProperty(propertyId, value); return(propertyset); }
internal static DBPropSet CreateProperty(Guid propertySet, int propertyId, bool required, object value) { ItagDBPROP dbprop = OleDbStructHelpers.CreateTagDbProp(propertyId, required, value); DBPropSet propertyset = new DBPropSet(1); propertyset.SetPropertySet(0, propertySet, new ItagDBPROP[1] { dbprop }); return(propertyset); }
static internal DBPropSet CreateProperty(Guid propertySet, int propertyId, bool required, object value) { tagDBPROP dbprop = new tagDBPROP(propertyId, required, value); DBPropSet propertyset = new DBPropSet(1); propertyset.SetPropertySet(0, propertySet, new tagDBPROP[1] { dbprop }); return(propertyset); }
private bool PropertiesOnCommand(bool throwNotSupported) { if (null != _icommandText) { return(true); } Debug.Assert(!_isPrepared, "null command isPrepared"); OleDbConnection connection = _connection; if (null == connection) { connection.CheckStateOpen(ODB.Properties); } if (!_trackingForClose) { _trackingForClose = true; connection.AddWeakReference(this, OleDbReferenceCollection.CommandTag); } _icommandText = connection.ICommandText(); if (null == _icommandText) { if (throwNotSupported || HasParameters()) { throw ODB.CommandTextNotSupported(connection.Provider, null); } return(false); } using (DBPropSet propSet = CommandPropertySets()) { if (null != propSet) { UnsafeNativeMethods.ICommandProperties icommandProperties = ICommandProperties(); OleDbHResult hr = icommandProperties.SetProperties(propSet.PropertySetCount, propSet); if (hr < 0) { SafeNativeMethods.Wrapper.ClearErrorInfo(); } } } return(true); }
private bool PropertiesOnCommand(bool throwNotSupported) { if (this._icommandText == null) { OleDbConnection connection = this._connection; if (connection == null) { connection.CheckStateOpen("Properties"); } if (!this._trackingForClose) { this._trackingForClose = true; connection.AddWeakReference(this, 1); } this._icommandText = connection.ICommandText(); if (this._icommandText == null) { if (throwNotSupported || this.HasParameters()) { throw ODB.CommandTextNotSupported(connection.Provider, null); } return(false); } using (DBPropSet set = this.CommandPropertySets()) { if (set != null) { System.Data.Common.UnsafeNativeMethods.ICommandProperties properties = this.ICommandProperties(); Bid.Trace("<oledb.ICommandProperties.SetProperties|API|OLEDB> %d#\n", this.ObjectID); OleDbHResult result = properties.SetProperties(set.PropertySetCount, set); Bid.Trace("<oledb.ICommandProperties.SetProperties|API|OLEDB|RET> %08X{HRESULT}\n", result); if (result < OleDbHResult.S_OK) { SafeNativeMethods.Wrapper.ClearErrorInfo(); } } } } return(true); }
internal void SetDataSourcePropertyValue(Guid propertySet, int propertyID, string description, bool required, object value) { CheckStateOpen(ADP.SetProperties); OleDbHResult hr; using (IDBPropertiesWrapper idbProperties = IDBProperties()) { using (DBPropSet propSet = DBPropSet.CreateProperty(propertySet, propertyID, required, value)) { hr = idbProperties.Value.SetProperties(propSet.PropertySetCount, propSet); if (hr < 0) { Exception e = OleDbConnection.ProcessResults(hr, null, this); if (OleDbHResult.DB_E_ERRORSOCCURRED == hr) { StringBuilder builder = new StringBuilder(); Debug.Assert(1 == propSet.PropertySetCount, "too many PropertySets"); tagDBPROP[] dbprops = propSet.GetPropertySet(0, out propertySet); Debug.Assert(1 == dbprops.Length, "too many Properties"); ODB.PropsetSetFailure(builder, description, dbprops[0].dwStatus); e = ODB.PropsetSetFailure(builder.ToString(), e); } if (null != e) { throw e; } } else { SafeNativeMethods.Wrapper.ClearErrorInfo(); } } } }
internal object GetDataSourcePropertyValue(Guid propertySet, int propertyID) { tagDBPROP[] gdbpropArray; using (IDBPropertiesWrapper wrapper = this.IDBProperties()) { using (PropertyIDSet set2 = new PropertyIDSet(propertySet, propertyID)) { OleDbHResult result; using (DBPropSet set = new DBPropSet(wrapper.Value, set2, out result)) { if (result < OleDbHResult.S_OK) { SafeNativeMethods.Wrapper.ClearErrorInfo(); } gdbpropArray = set.GetPropertySet(0, out propertySet); } } } if (gdbpropArray[0].dwStatus == OleDbPropertyStatus.Ok) { return(gdbpropArray[0].vValue); } return(gdbpropArray[0].dwStatus); }
private DBPropSet CommandPropertySets() { DBPropSet set = null; bool flag = CommandBehavior.Default != (CommandBehavior.KeyInfo & this.commandBehavior); int num = this._executeQuery ? (flag ? 4 : 2) : 1; if (0 < num) { set = new DBPropSet(1); tagDBPROP[] properties = new tagDBPROP[num]; properties[0] = new tagDBPROP(0x22, false, this.CommandTimeout); if (this._executeQuery) { properties[1] = new tagDBPROP(0xe7, false, 2); if (flag) { properties[2] = new tagDBPROP(0xee, false, flag); properties[3] = new tagDBPROP(0x7b, false, true); } } set.SetPropertySet(0, OleDbPropertySetGuid.Rowset, properties); } return(set); }
static internal DBPropSet CreateProperty(Guid propertySet, int propertyId, bool required, object value) { tagDBPROP dbprop = new tagDBPROP(propertyId, required, value); DBPropSet propertyset = new DBPropSet(1); propertyset.SetPropertySet(0, propertySet, new tagDBPROP[1] { dbprop }); return propertyset; }
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 DBPropSet CommandPropertySets() { DBPropSet propSet = null; bool keyInfo = (0 != (CommandBehavior.KeyInfo & this.commandBehavior)); // always set the CommandTimeout value? int count = (_executeQuery ? (keyInfo ? 4 : 2) : 1); if (0 < count) { propSet = new DBPropSet(1); tagDBPROP[] dbprops = new tagDBPROP[count]; dbprops[0] = new tagDBPROP(ODB.DBPROP_COMMANDTIMEOUT, false, CommandTimeout); if (_executeQuery) { // 'Microsoft.Jet.OLEDB.4.0' default is DBPROPVAL_AO_SEQUENTIAL dbprops[1] = new tagDBPROP(ODB.DBPROP_ACCESSORDER, false, ODB.DBPROPVAL_AO_RANDOM); // MDAC 73030 if (keyInfo) { // 'Unique Rows' property required for SQLOLEDB to retrieve things like 'BaseTableName' dbprops[2] = new tagDBPROP(ODB.DBPROP_UNIQUEROWS, false, keyInfo); // otherwise 'Microsoft.Jet.OLEDB.4.0' doesn't support IColumnsRowset dbprops[3] = new tagDBPROP(ODB.DBPROP_IColumnsRowset, false, true); } } propSet.SetPropertySet(0, OleDbPropertySetGuid.Rowset, dbprops); } return propSet; }
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; }
private int ExecuteTableDirect(CommandBehavior behavior, out object executeResult) { this.commandBehavior = behavior; executeResult = null; OleDbHResult result = OleDbHResult.S_OK; StringMemHandle handle = null; bool success = false; RuntimeHelpers.PrepareConstrainedRegions(); try { handle = new StringMemHandle(this.ExpandCommandText()); handle.DangerousAddRef(ref success); if (success) { tagDBID pTableID = new tagDBID { uGuid = Guid.Empty, eKind = 2, ulPropid = handle.DangerousGetHandle() }; using (IOpenRowsetWrapper wrapper = this._connection.IOpenRowset()) { using (DBPropSet set = this.CommandPropertySets()) { if (set != null) { Bid.Trace("<oledb.IOpenRowset.OpenRowset|API|OLEDB> %d#, IID_IRowset\n", this.ObjectID); bool flag2 = false; RuntimeHelpers.PrepareConstrainedRegions(); try { set.DangerousAddRef(ref flag2); result = wrapper.Value.OpenRowset(ADP.PtrZero, pTableID, ADP.PtrZero, ref ODB.IID_IRowset, set.PropertySetCount, set.DangerousGetHandle(), out executeResult); } finally { if (flag2) { set.DangerousRelease(); } } Bid.Trace("<oledb.IOpenRowset.OpenRowset|API|OLEDB|RET> %08X{HRESULT}", result); if (OleDbHResult.DB_E_ERRORSOCCURRED == result) { Bid.Trace("<oledb.IOpenRowset.OpenRowset|API|OLEDB> %d#, IID_IRowset\n", this.ObjectID); result = wrapper.Value.OpenRowset(ADP.PtrZero, pTableID, ADP.PtrZero, ref ODB.IID_IRowset, 0, IntPtr.Zero, out executeResult); Bid.Trace("<oledb.IOpenRowset.OpenRowset|API|OLEDB|RET> %08X{HRESULT}", result); } } else { Bid.Trace("<oledb.IOpenRowset.OpenRowset|API|OLEDB> %d#, IID_IRowset\n", this.ObjectID); result = wrapper.Value.OpenRowset(ADP.PtrZero, pTableID, ADP.PtrZero, ref ODB.IID_IRowset, 0, IntPtr.Zero, out executeResult); Bid.Trace("<oledb.IOpenRowset.OpenRowset|API|OLEDB|RET> %08X{HRESULT}", result); } } } } } finally { if (success) { handle.DangerousRelease(); } } this.ProcessResults(result); this._recordsAffected = ADP.RecordsUnaffected; return(1); }
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; }
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 int ExecuteTableDirect(CommandBehavior behavior, out object executeResult) { this.commandBehavior = behavior; executeResult = null; OleDbHResult hr = OleDbHResult.S_OK; StringMemHandle sptr = null; bool mustReleaseStringHandle = false; RuntimeHelpers.PrepareConstrainedRegions(); try { sptr = new StringMemHandle(ExpandCommandText()); sptr.DangerousAddRef(ref mustReleaseStringHandle); if (mustReleaseStringHandle) { tagDBID tableID = new tagDBID(); tableID.uGuid = Guid.Empty; tableID.eKind = ODB.DBKIND_NAME; tableID.ulPropid = sptr.DangerousGetHandle(); using (IOpenRowsetWrapper iopenRowset = _connection.IOpenRowset()) { using (DBPropSet propSet = CommandPropertySets()) { if (null != propSet) { bool mustRelease = false; RuntimeHelpers.PrepareConstrainedRegions(); try { propSet.DangerousAddRef(ref mustRelease); hr = iopenRowset.Value.OpenRowset(ADP.PtrZero, tableID, ADP.PtrZero, ref ODB.IID_IRowset, propSet.PropertySetCount, propSet.DangerousGetHandle(), out executeResult); } finally { if (mustRelease) { propSet.DangerousRelease(); } } if (OleDbHResult.DB_E_ERRORSOCCURRED == hr) { hr = iopenRowset.Value.OpenRowset(ADP.PtrZero, tableID, ADP.PtrZero, ref ODB.IID_IRowset, 0, IntPtr.Zero, out executeResult); } } else { hr = iopenRowset.Value.OpenRowset(ADP.PtrZero, tableID, ADP.PtrZero, ref ODB.IID_IRowset, 0, IntPtr.Zero, out executeResult); } } } } } finally { if (mustReleaseStringHandle) { sptr.DangerousRelease(); } } ProcessResults(hr); _recordsAffected = ADP.RecordsUnaffected; return(ODB.ExecutedIRowset); }
private DBPropSet CommandPropertySets() { DBPropSet set = null; bool flag = CommandBehavior.Default != (CommandBehavior.KeyInfo & this.commandBehavior); int num = this._executeQuery ? (flag ? 4 : 2) : 1; if (0 < num) { set = new DBPropSet(1); tagDBPROP[] properties = new tagDBPROP[num]; properties[0] = new tagDBPROP(0x22, false, this.CommandTimeout); if (this._executeQuery) { properties[1] = new tagDBPROP(0xe7, false, 2); if (flag) { properties[2] = new tagDBPROP(0xee, false, flag); properties[3] = new tagDBPROP(0x7b, false, true); } } set.SetPropertySet(0, OleDbPropertySetGuid.Rowset, properties); } return set; }
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> 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; }
internal static DBPropSet CreateProperty(Guid propertySet, int propertyId, bool required, object value) { tagDBPROP gdbprop = new tagDBPROP(propertyId, required, value); DBPropSet set = new DBPropSet(1); set.SetPropertySet(0, propertySet, new tagDBPROP[] { gdbprop }); return set; }
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; }