本文整理汇总了C#中Npgsql.NpgsqlConnector.ClearTransaction方法的典型用法代码示例。如果您正苦于以下问题:C# NpgsqlConnector.ClearTransaction方法的具体用法?C# NpgsqlConnector.ClearTransaction怎么用?C# NpgsqlConnector.ClearTransaction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Npgsql.NpgsqlConnector
的用法示例。
在下文中一共展示了NpgsqlConnector.ClearTransaction方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UngetConnector
/// <summary>
/// Put a pooled connector into the pool queue.
/// </summary>
/// <param name="Connection">Connection <paramref name="Connector"/> is leased to.</param>
/// <param name="Connector">Connector to pool</param>
private void UngetConnector(NpgsqlConnection Connection, NpgsqlConnector Connector)
{
ConnectorQueue queue;
// Find the queue.
// As we are handling all possible queues, we have to lock everything...
lock (locker)
{
PooledConnectors.TryGetValue(Connection.ConnectionString, out queue);
}
if (queue == null)
{
Connector.Close(); // Release connection to postgres
return; // Queue may be emptied by connection problems. See ClearPool below.
}
Connector.ProvideClientCertificatesCallback -= Connection.ProvideClientCertificatesCallbackDelegate;
Connector.CertificateSelectionCallback -= Connection.CertificateSelectionCallbackDelegate;
Connector.CertificateValidationCallback -= Connection.CertificateValidationCallbackDelegate;
Connector.PrivateKeySelectionCallback -= Connection.PrivateKeySelectionCallbackDelegate;
Connector.ValidateRemoteCertificateCallback -= Connection.ValidateRemoteCertificateCallbackDelegate;
/*bool inQueue = false;
lock (queue)
{
inQueue = queue.Busy.ContainsKey(Connector);
queue.Busy.Remove(Connector);
}
*/
if (!Connector.IsConnected)
{
if (Connector.Transaction != null)
{
Connector.ClearTransaction();
}
Connector.Close();
}
else
{
if (Connector.Transaction != null)
{
try
{
Connector.Transaction.Rollback();
}
catch
{
Connector.Close();
}
}
}
bool inQueue = queue.Busy.ContainsKey(Connector);
if (Connector.State == ConnectorState.Ready)
{
//If thread is good
if ((Thread.CurrentThread.ThreadState & (ThreadState.Aborted | ThreadState.AbortRequested)) == 0)
{
// Release all resources associated with this connector.
try
{
Connector.ReleaseResources();
}
catch (Exception)
{
//If the connector fails to release its resources then it is probably broken, so make sure we don't add it to the queue.
// Usually it already won't be in the queue as it would of broken earlier
inQueue = false;
Connector.Close();
}
}
else
{
//Thread is being aborted, this connection is possibly broken. So kill it rather than returning it to the pool
inQueue = false;
Connector.Close();
}
}
// Check if Connector should return to the queue of available connectors. If not, this connector is invalid and should
// only be removed from the busy queue which effectvely removes it from the pool.
if (inQueue)
lock (queue)
{
queue.Busy.Remove(Connector);
queue.Available.Enqueue(Connector);
}
else
lock (queue)
//.........这里部分代码省略.........
示例2: ReleaseConnector
/// <summary>
/// Releases a connector, possibly back to the pool for future use.
/// </summary>
/// <remarks>
/// Pooled connectors will be put back into the pool if there is room.
/// </remarks>
/// <param name="connection">Connection to which the connector is leased.</param>
/// <param name="connector">The connector to release.</param>
internal void ReleaseConnector(NpgsqlConnection connection, NpgsqlConnector connector)
{
Contract.Requires(connector.IsReady || connector.IsClosed || connector.IsBroken);
ConnectorQueue queue;
// Find the queue.
// As we are handling all possible queues, we have to lock everything...
lock (locker)
{
PooledConnectors.TryGetValue(connection.ConnectionString, out queue);
}
if (queue == null)
{
connector.Close(); // Release connection to postgres
return; // Queue may be emptied by connection problems. See ClearPool below.
}
/*bool inQueue = false;
lock (queue)
{
inQueue = queue.Busy.ContainsKey(Connector);
queue.Busy.Remove(Connector);
}
*/
bool inQueue = queue.Busy.ContainsKey(connector);
if (connector.IsBroken || connector.IsClosed)
{
if (connector.InTransaction)
{
connector.ClearTransaction();
}
connector.Close();
inQueue = false;
}
else
{
Contract.Assert(connector.IsReady);
//If thread is good
if ((Thread.CurrentThread.ThreadState & (ThreadState.Aborted | ThreadState.AbortRequested)) == 0)
{
// Release all resources associated with this connector.
try {
connector.Reset();
} catch {
connector.Close();
inQueue = false;
}
} else {
//Thread is being aborted, this connection is possibly broken. So kill it rather than returning it to the pool
inQueue = false;
connector.Close();
}
}
// Check if Connector should return to the queue of available connectors. If not, this connector is invalid and should
// only be removed from the busy queue which effectvely removes it from the pool.
if (inQueue)
lock (queue)
{
queue.Busy.Remove(connector);
queue.Available.Enqueue(connector);
}
else
lock (queue)
{
queue.Busy.Remove(connector);
}
connector.ProvideClientCertificatesCallback = null;
connector.UserCertificateValidationCallback = null;
}