本文整理汇总了C#中System.Data.ProviderBase.DbConnectionInternal类的典型用法代码示例。如果您正苦于以下问题:C# DbConnectionInternal类的具体用法?C# DbConnectionInternal怎么用?C# DbConnectionInternal使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DbConnectionInternal类属于System.Data.ProviderBase命名空间,在下文中一共展示了DbConnectionInternal类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateMetaDataFactory
protected override DbMetaDataFactory CreateMetaDataFactory(DbConnectionInternal internalConnection, out bool cacheMetaDataFactory)
{
cacheMetaDataFactory = false;
OleDbConnectionInternal internal2 = (OleDbConnectionInternal) internalConnection;
OleDbConnection connection = internal2.Connection;
NameValueCollection section = (NameValueCollection) System.Configuration.PrivilegedConfigurationManager.GetSection("system.data.oledb");
Stream xMLStream = null;
string dataSourcePropertyValue = connection.GetDataSourcePropertyValue(OleDbPropertySetGuid.DataSourceInfo, 0x60) as string;
if (section != null)
{
string[] values = null;
string name = null;
if (dataSourcePropertyValue != null)
{
name = dataSourcePropertyValue + ":MetaDataXml";
values = section.GetValues(name);
}
if (values == null)
{
name = "defaultMetaDataXml";
values = section.GetValues(name);
}
if (values != null)
{
xMLStream = ADP.GetXmlStreamFromValues(values, name);
}
}
if (xMLStream == null)
{
xMLStream = Assembly.GetExecutingAssembly().GetManifestResourceStream("System.Data.OleDb.OleDbMetaData.xml");
cacheMetaDataFactory = true;
}
return new OleDbMetaDataFactory(xMLStream, internal2.ServerVersion, internal2.ServerVersion, internal2.GetSchemaRowsetInformation());
}
示例2: CreateMetaDataFactory
override protected DbMetaDataFactory CreateMetaDataFactory(DbConnectionInternal internalConnection, out bool cacheMetaDataFactory){
Debug.Assert (internalConnection != null,"internalConnection may not be null.");
cacheMetaDataFactory = false;
OdbcConnection odbcOuterConnection = ((OdbcConnectionOpen)internalConnection).OuterConnection;
Debug.Assert(odbcOuterConnection != null,"outer connection may not be null.");
NameValueCollection settings = (NameValueCollection)PrivilegedConfigurationManager.GetSection("system.data.odbc");
Stream XMLStream =null;
// get the DBMS Name
object driverName = null;
string stringValue = odbcOuterConnection.GetInfoStringUnhandled(ODBC32.SQL_INFO.DRIVER_NAME);
if (stringValue != null) {
driverName = stringValue;
}
if (settings != null){
string [] values = null;
string metaDataXML = null;
// first try to get the provider specific xml
// if driver name is not supported we can't build the settings key needed to
// get the provider specific XML path
if (driverName != null){
metaDataXML = ((string)driverName) + _MetaData;
values = settings.GetValues(metaDataXML);
}
// if we did not find provider specific xml see if there is new default xml
if (values == null) {
metaDataXML = _defaultMetaDataXml;
values = settings.GetValues(metaDataXML);
}
// If there is an XML file get it
if (values != null) {
XMLStream = ADP.GetXmlStreamFromValues(values,metaDataXML);
}
}
// use the embedded xml if the user did not over ride it
if (XMLStream == null){
XMLStream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("System.Data.Odbc.OdbcMetaData.xml");
cacheMetaDataFactory = true;
}
Debug.Assert (XMLStream != null,"XMLstream may not be null.");
String versionString = odbcOuterConnection.GetInfoStringUnhandled(ODBC32.SQL_INFO.DBMS_VER);
return new OdbcMetaDataFactory (XMLStream,
versionString,
versionString,
odbcOuterConnection);
}
示例3: CreateMetaDataFactory
override protected DbMetaDataFactory CreateMetaDataFactory(DbConnectionInternal internalConnection, out bool cacheMetaDataFactory){
Debug.Assert (internalConnection != null,"internalConnection may not be null.");
cacheMetaDataFactory = false;
OleDbConnectionInternal oleDbInternalConnection = (OleDbConnectionInternal) internalConnection;
OleDbConnection oleDbOuterConnection = oleDbInternalConnection.Connection;
Debug.Assert(oleDbOuterConnection != null,"outer connection may not be null.");
NameValueCollection settings = (NameValueCollection)PrivilegedConfigurationManager.GetSection("system.data.oledb");
Stream XMLStream =null;
String providerFileName = oleDbOuterConnection.GetDataSourcePropertyValue(OleDbPropertySetGuid.DataSourceInfo,ODB.DBPROP_PROVIDERFILENAME) as string;
if (settings != null){
string [] values = null;
string metaDataXML = null;
// first try to get the provider specific xml
// if providerfilename is not supported we can't build the settings key needed to
// get the provider specific XML path
if (providerFileName != null){
metaDataXML = providerFileName + _metaDataXml;
values = settings.GetValues(metaDataXML);
}
// if we did not find provider specific xml see if there is new default xml
if (values == null) {
metaDataXML =_defaultMetaDataXml;
values = settings.GetValues(metaDataXML);
}
// If there is new XML get it
if (values != null) {
XMLStream = ADP.GetXmlStreamFromValues(values,metaDataXML);
}
}
// if the xml was not obtained from machine.config use the embedded XML resource
if (XMLStream == null) {
XMLStream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("System.Data.OleDb.OleDbMetaData.xml");
cacheMetaDataFactory = true;
}
Debug.Assert (XMLStream != null,"XMLstream may not be null.");
// using the ServerVersion as the NormalizedServerVersion. Doing this for two reasons
// 1) The Spec for DBPROP_DBMSVER normalizes the ServerVersion
// 2) for OLE DB its the only game in town
return new OleDbMetaDataFactory (XMLStream,
oleDbInternalConnection.ServerVersion,
oleDbInternalConnection.ServerVersion,
oleDbInternalConnection.GetSchemaRowsetInformation());
}
示例4: ConnectionString_Set
private void ConnectionString_Set(DbConnectionPoolKey key)
{
DbConnectionOptions connectionOptions = null;
System.Data.ProviderBase.DbConnectionPoolGroup poolGroup = ConnectionFactory.GetConnectionPoolGroup(key, null, ref connectionOptions);
DbConnectionInternal connectionInternal = InnerConnection;
bool flag = connectionInternal.AllowSetConnectionString;
if (flag)
{
flag = SetInnerConnectionFrom(DbConnectionClosedBusy.SingletonInstance, connectionInternal);
if (flag)
{
_userConnectionOptions = connectionOptions;
_poolGroup = poolGroup;
_innerConnection = DbConnectionClosedNeverOpened.SingletonInstance;
}
}
if (!flag)
{
throw ADP.OpenConnectionPropertySet(ADP.ConnectionString, connectionInternal.State);
}
}
示例5: CreateMetaDataFactory
protected override DbMetaDataFactory CreateMetaDataFactory(DbConnectionInternal internalConnection, out bool cacheMetaDataFactory)
{
cacheMetaDataFactory = false;
OdbcConnection outerConnection = ((OdbcConnectionOpen) internalConnection).OuterConnection;
NameValueCollection section = (NameValueCollection) System.Configuration.PrivilegedConfigurationManager.GetSection("system.data.odbc");
Stream xMLStream = null;
object obj2 = null;
string infoStringUnhandled = outerConnection.GetInfoStringUnhandled(ODBC32.SQL_INFO.DRIVER_NAME);
if (infoStringUnhandled != null)
{
obj2 = infoStringUnhandled;
}
if (section != null)
{
string[] values = null;
string name = null;
if (obj2 != null)
{
name = ((string) obj2) + ":MetaDataXml";
values = section.GetValues(name);
}
if (values == null)
{
name = "defaultMetaDataXml";
values = section.GetValues(name);
}
if (values != null)
{
xMLStream = ADP.GetXmlStreamFromValues(values, name);
}
}
if (xMLStream == null)
{
xMLStream = Assembly.GetExecutingAssembly().GetManifestResourceStream("System.Data.Odbc.OdbcMetaData.xml");
cacheMetaDataFactory = true;
}
string serverVersion = outerConnection.GetInfoStringUnhandled(ODBC32.SQL_INFO.DBMS_VER);
return new OdbcMetaDataFactory(xMLStream, serverVersion, serverVersion, outerConnection);
}
示例6: SetInnerConnectionFrom
override internal bool SetInnerConnectionFrom(DbConnection owningObject, DbConnectionInternal to, DbConnectionInternal from) {
SqlConnection c = (owningObject as SqlConnection);
if (null != c) {
return c.SetInnerConnectionFrom(to, from);
}
return false;
}
示例7: ReplaceConnection
/// <summary>
/// Creates a new connection to replace an existing connection
/// </summary>
/// <param name="owningObject">Outer connection that currently owns <paramref name="oldConnection"/></param>
/// <param name="userOptions">Options used to create the new connection</param>
/// <param name="oldConnection">Inner connection that will be replaced</param>
/// <returns>A new inner connection that is attached to the <paramref name="owningObject"/></returns>
internal DbConnectionInternal ReplaceConnection(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)
{
DbConnectionInternal newConnection = UserCreateRequest(owningObject, userOptions, oldConnection);
if (newConnection != null)
{
PrepareConnection(owningObject, newConnection);
oldConnection.PrepareForReplaceConnection();
oldConnection.DeactivateConnection();
oldConnection.Dispose();
}
return newConnection;
}
示例8: TryGetConnection
private bool TryGetConnection(DbConnection owningObject, uint waitForMultipleObjectsTimeout, bool allowCreate, bool onlyOneCheckConnection, DbConnectionOptions userOptions, out DbConnectionInternal connection)
{
DbConnectionInternal obj = null;
if (null == obj)
{
Interlocked.Increment(ref _waitCount);
do
{
int waitResult = BOGUS_HANDLE;
try
{
try
{
}
finally
{
waitResult = WaitHandle.WaitAny(_waitHandles.GetHandles(allowCreate), unchecked((int)waitForMultipleObjectsTimeout));
}
// From the WaitAny docs: "If more than one object became signaled during
// the call, this is the array index of the signaled object with the
// smallest index value of all the signaled objects." This is important
// so that the free object signal will be returned before a creation
// signal.
switch (waitResult)
{
case WaitHandle.WaitTimeout:
Interlocked.Decrement(ref _waitCount);
connection = null;
return false;
case ERROR_HANDLE:
// Throw the error that PoolCreateRequest stashed.
Interlocked.Decrement(ref _waitCount);
throw TryCloneCachedException();
case CREATION_HANDLE:
try
{
obj = UserCreateRequest(owningObject, userOptions);
}
catch
{
if (null == obj)
{
Interlocked.Decrement(ref _waitCount);
}
throw;
}
finally
{
// Ensure that we release this waiter, regardless
// of any exceptions that may be thrown.
if (null != obj)
{
Interlocked.Decrement(ref _waitCount);
}
}
if (null == obj)
{
// If we were not able to create an object, check to see if
// we reached MaxPoolSize. If so, we will no longer wait on
// the CreationHandle, but instead wait for a free object or
// the timeout.
if (Count >= MaxPoolSize && 0 != MaxPoolSize)
{
if (!ReclaimEmancipatedObjects())
{
// modify handle array not to wait on creation mutex anymore
Debug.Assert(2 == CREATION_HANDLE, "creation handle changed value");
allowCreate = false;
}
}
}
break;
case SEMAPHORE_HANDLE:
//
// guaranteed available inventory
//
Interlocked.Decrement(ref _waitCount);
obj = GetFromGeneralPool();
if ((obj != null) && (!obj.IsConnectionAlive()))
{
DestroyObject(obj);
obj = null; // Setting to null in case creating a new object fails
if (onlyOneCheckConnection)
{
if (_waitHandles.CreationSemaphore.WaitOne(unchecked((int)waitForMultipleObjectsTimeout)))
{
try
{
obj = UserCreateRequest(owningObject, userOptions);
}
//.........这里部分代码省略.........
示例9: DestroyObject
internal void DestroyObject(DbConnectionInternal obj)
{
// A connection with a delegated transaction cannot be disposed of
// until the delegated transaction has actually completed. Instead,
// we simply leave it alone; when the transaction completes, it will
// come back through PutObjectFromTransactedPool, which will call us
// again.
bool removed = false;
lock (_objectList)
{
removed = _objectList.Remove(obj);
Debug.Assert(removed, "attempt to DestroyObject not in list");
_totalObjects = _objectList.Count;
}
if (removed)
{
}
obj.Dispose();
}
示例10: CreateObject
private DbConnectionInternal CreateObject(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)
{
DbConnectionInternal newObj = null;
try
{
newObj = _connectionFactory.CreatePooledConnection(this, owningObject, _connectionPoolGroup.ConnectionOptions, _connectionPoolGroup.PoolKey, userOptions);
if (null == newObj)
{
throw ADP.InternalError(ADP.InternalErrorCode.CreateObjectReturnedNull); // CreateObject succeeded, but null object
}
if (!newObj.CanBePooled)
{
throw ADP.InternalError(ADP.InternalErrorCode.NewObjectCannotBePooled); // CreateObject succeeded, but non-poolable object
}
newObj.PrePush(null);
lock (_objectList)
{
if ((oldConnection != null) && (oldConnection.Pool == this))
{
_objectList.Remove(oldConnection);
}
_objectList.Add(newObj);
_totalObjects = _objectList.Count;
}
// If the old connection belonged to another pool, we need to remove it from that
if (oldConnection != null)
{
var oldConnectionPool = oldConnection.Pool;
if (oldConnectionPool != null && oldConnectionPool != this)
{
Debug.Assert(oldConnectionPool._state == State.ShuttingDown, "Old connections pool should be shutting down");
lock (oldConnectionPool._objectList)
{
oldConnectionPool._objectList.Remove(oldConnection);
oldConnectionPool._totalObjects = oldConnectionPool._objectList.Count;
}
}
}
// Reset the error wait:
_errorWait = ERROR_WAIT_DEFAULT;
}
catch (Exception e)
{
if (!ADP.IsCatchableExceptionType(e))
{
throw;
}
newObj = null; // set to null, so we do not return bad new object
// Failed to create instance
_resError = e;
// Make sure the timer starts even if ThreadAbort occurs after setting the ErrorEvent.
// timer allocation has to be done out of CER block
Timer t = new Timer(new TimerCallback(this.ErrorCallback), null, Timeout.Infinite, Timeout.Infinite);
bool timerIsNotDisposed;
try { }
finally
{
_waitHandles.ErrorEvent.Set();
_errorOccurred = true;
// Enable the timer.
// Note that the timer is created to allow periodic invocation. If ThreadAbort occurs in the middle of ErrorCallback,
// the timer will restart. Otherwise, the timer callback (ErrorCallback) destroys the timer after resetting the error to avoid second callback.
_errorTimer = t;
timerIsNotDisposed = t.Change(_errorWait, _errorWait);
}
Debug.Assert(timerIsNotDisposed, "ErrorCallback timer has been disposed");
if (30000 < _errorWait)
{
_errorWait = 60000;
}
else
{
_errorWait *= 2;
}
throw;
}
return newObj;
}
示例11: PutObject
internal void PutObject(DbConnectionInternal obj, object owningObject)
{
Debug.Assert(null != obj, "null obj?");
// Once a connection is closing (which is the state that we're in at
// this point in time) you cannot delegate a transaction to or enlist
// a transaction in it, so we can correctly presume that if there was
// not a delegated or enlisted transaction to start with, that there
// will not be a delegated or enlisted transaction once we leave the
// lock.
lock (obj)
{
// Calling PrePush prevents the object from being reclaimed
// once we leave the lock, because it sets _pooledCount such
// that it won't appear to be out of the pool. What that
// means, is that we're now responsible for this connection:
// it won't get reclaimed if we drop the ball somewhere.
obj.PrePush(owningObject);
}
DeactivateObject(obj);
}
示例12: CreateMetaDataFactory
protected virtual DbMetaDataFactory CreateMetaDataFactory (DbConnectionInternal internalConnection)
{
throw new NotImplementedException ();
}
示例13: PutNewObject
internal void PutNewObject(DbConnectionInternal obj)
{
Debug.Assert(null != obj, "why are we adding a null object to the pool?");
// Debug.Assert(obj.CanBePooled, "non-poolable object in pool");
_stackNew.Push(obj);
_waitHandles.PoolSemaphore.Release(1);
}
示例14: SetInnerConnectionEvent
internal void SetInnerConnectionEvent(System.Data.ProviderBase.DbConnectionInternal to)
{
ConnectionState originalState = this._innerConnection.State & ConnectionState.Open;
ConnectionState currentState = to.State & ConnectionState.Open;
if ((originalState != currentState) && (currentState == ConnectionState.Closed))
{
this._closeCount++;
}
this._innerConnection = to;
if ((originalState == ConnectionState.Closed) && (ConnectionState.Open == currentState))
{
this.OnStateChange(System.Data.ProviderBase.DbConnectionInternal.StateChangeOpen);
}
else if ((ConnectionState.Open == originalState) && (currentState == ConnectionState.Closed))
{
this.OnStateChange(System.Data.ProviderBase.DbConnectionInternal.StateChangeClosed);
}
else if (originalState != currentState)
{
this.OnStateChange(new StateChangeEventArgs(originalState, currentState));
}
}
示例15: UserCreateRequest
private DbConnectionInternal UserCreateRequest(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection = null)
{
// called by user when they were not able to obtain a free object but
// instead obtained creation mutex
DbConnectionInternal obj = null;
if (ErrorOccurred)
{
throw TryCloneCachedException();
}
else
{
if ((oldConnection != null) || (Count < MaxPoolSize) || (0 == MaxPoolSize))
{
// If we have an odd number of total objects, reclaim any dead objects.
// If we did not find any objects to reclaim, create a new one.
if ((oldConnection != null) || (Count & 0x1) == 0x1 || !ReclaimEmancipatedObjects())
obj = CreateObject(owningObject, userOptions, oldConnection);
}
return obj;
}
}