本文整理汇总了C#中Npgsql.NpgsqlConnector.Close方法的典型用法代码示例。如果您正苦于以下问题:C# NpgsqlConnector.Close方法的具体用法?C# NpgsqlConnector.Close怎么用?C# NpgsqlConnector.Close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Npgsql.NpgsqlConnector
的用法示例。
在下文中一共展示了NpgsqlConnector.Close方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ProcessBackendResponsesEnum
///<summary>
/// This method is responsible to handle all protocol messages sent from the backend.
/// It holds all the logic to do it.
/// To exchange data, it uses a Mediator object from which it reads/writes information
/// to handle backend requests.
/// </summary>
///
internal IEnumerable<IServerResponseObject> ProcessBackendResponsesEnum(NpgsqlConnector context)
{
try
{
// Process commandTimeout behavior.
if ((context.Mediator.CommandTimeout > 0) &&
(!context.Socket.Poll(1000000*context.Mediator.CommandTimeout, SelectMode.SelectRead)))
{
// If timeout occurs when establishing the session with server then
// throw an exception instead of trying to cancel query. This helps to prevent loop as CancelRequest will also try to stablish a connection and sends commands.
if (!((this is NpgsqlStartupState || this is NpgsqlConnectedState || context.CancelRequestCalled)))
{
try
{
context.CancelRequest();
foreach (IServerResponseObject obj in ProcessBackendResponsesEnum(context))
{
if (obj is IDisposable)
{
(obj as IDisposable).Dispose();
}
}
}
catch(Exception ex)
{
}
//We should have gotten an error from CancelRequest(). Whether we did or not, what we
//really have is a timeout exception, and that will be less confusing to the user than
//"operation cancelled by user" or similar, so whatever the case, that is what we'll throw.
// Changed message again to report about the two possible timeouts: connection or command as the establishment timeout only was confusing users when the timeout was a command timeout.
}
throw new NpgsqlException(resman.GetString("Exception_ConnectionOrCommandTimeout"));
}
switch (context.BackendProtocolVersion)
{
case ProtocolVersion.Version2:
return ProcessBackendResponses_Ver_2(context);
case ProtocolVersion.Version3:
return ProcessBackendResponses_Ver_3(context);
default:
throw new NpgsqlException(resman.GetString("Exception_UnknownProtocol"));
}
}
catch(ThreadAbortException)
{
try
{
context.CancelRequest();
context.Close();
}
catch {}
throw;
}
}
示例2: CancelRequest
/// <summary>
/// Creates another connector and sends a cancel request through it for this connector.
/// </summary>
internal void CancelRequest()
{
var cancelConnector = new NpgsqlConnector(_settings, false);
try
{
cancelConnector.RawOpen(cancelConnector.ConnectionTimeout*1000);
cancelConnector.SendSingleMessage(new CancelRequestMessage(BackendProcessId, BackendSecretKey));
}
finally
{
cancelConnector.Close();
}
}
示例3: ProcessExistingBackendResponses
internal IEnumerable<IServerResponseObject> ProcessExistingBackendResponses(NpgsqlConnector context)
{
try
{
return ProcessBackendResponses_Ver_3(context);
}
catch (ThreadAbortException)
{
try
{
context.CancelRequest();
context.Close();
}
catch { }
throw;
}
}
示例4: GetSharedConnector
/*
/// <summary>
/// Find an available shared connector in the shared pool, or create
/// a new one if none found.
/// </summary>
private NpgsqlConnector GetSharedConnector(NpgsqlConnection Connection)
{
// To be implemented
return null;
}
*/
/// <summary>
/// Put a pooled connector into the pool queue.
/// </summary>
/// <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.IsInitialized)
{
if (Connector.Transaction != null)
{
Connector.Transaction.Cancel();
}
Connector.Close();
}
else
{
if (Connector.Transaction != null)
{
try
{
Connector.Transaction.Rollback();
}
catch
{
Connector.Close();
}
}
}
if (Connector.State == ConnectionState.Open)
{
//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;
}
if (inQueue)
lock (queue)
{
queue.Available.Enqueue(Connector);
}
else
Connector.Close();
}
else
{
//Thread is being aborted, this connection is possibly broken. So kill it rather than returning it to the pool
Connector.Close();
//.........这里部分代码省略.........
示例5: 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;
}
示例6: UngetNonPooledConnector
/// <summary>
/// Close the connector.
/// </summary>
/// <param name="Connection"></param>
/// <param name="Connector">Connector to release</param>
private static void UngetNonPooledConnector(NpgsqlConnection Connection, NpgsqlConnector Connector)
{
Connector.ProvideClientCertificatesCallback -= Connection.ProvideClientCertificatesCallbackDelegate;
Connector.CertificateSelectionCallback -= Connection.CertificateSelectionCallbackDelegate;
Connector.CertificateValidationCallback -= Connection.CertificateValidationCallbackDelegate;
Connector.PrivateKeySelectionCallback -= Connection.PrivateKeySelectionCallbackDelegate;
if (Connector.Transaction != null)
{
Connector.Transaction.Cancel();
}
Connector.Close();
}
示例7: UngetPooledConnector
/// <summary>
/// Put a pooled connector into the pool queue.
/// </summary>
/// <param name="Connector">Connector to pool</param>
private void UngetPooledConnector(NpgsqlConnection Connection, NpgsqlConnector Connector)
{
ConnectorQueue Queue;
// Find the queue.
Queue = (ConnectorQueue)PooledConnectors[Connector.ConnectionString.ToString()];
if (Queue == null)
return; // Queue may be emptied by connection problems. See ClearPool below.
Connector.CertificateSelectionCallback -= Connection.CertificateSelectionCallbackDelegate;
Connector.CertificateValidationCallback -= Connection.CertificateValidationCallbackDelegate;
Connector.PrivateKeySelectionCallback -= Connection.PrivateKeySelectionCallbackDelegate;
Queue.UseCount--;
if (! Connector.IsInitialized)
{
if (Connector.Transaction != null)
{
Connector.Transaction.Cancel();
}
Connector.Close();
}
else
{
if (Connector.Transaction != null)
{
try
{
Connector.Transaction.Rollback();
}
catch {
Connector.Close()
;
}
}
}
if (Connector.State == System.Data.ConnectionState.Open)
{
// Release all resources associated with this connector.
Connector.ReleaseResources();
Queue.Enqueue(Connector);
}
}
示例8: ProcessBackendResponsesEnum
///<summary>
/// This method is responsible to handle all protocol messages sent from the backend.
/// It holds all the logic to do it.
/// To exchange data, it uses a Mediator object from which it reads/writes information
/// to handle backend requests.
/// </summary>
///
internal IEnumerable<IServerResponseObject> ProcessBackendResponsesEnum(NpgsqlConnector context)
{
try
{
// Flush buffers to the wire.
context.Stream.Flush();
// Process commandTimeout behavior.
if ((context.Mediator.BackendCommandTimeout > 0) &&
(!CheckForContextSocketAvailability(context, SelectMode.SelectRead)))
{
// If timeout occurs when establishing the session with server then
// throw an exception instead of trying to cancel query. This helps to prevent loop as
// CancelRequest will also try to stablish a connection and sends commands.
if (!((this is NpgsqlStartupState || this is NpgsqlConnectedState)))
{
try
{
context.CancelRequest();
ProcessAndDiscardBackendResponses(context);
}
catch(Exception)
{
}
// We should have gotten an error from CancelRequest(). Whether we did or not, what we
// really have is a timeout exception, and that will be less confusing to the user than
// "operation cancelled by user" or similar, so whatever the case, that is what we'll throw.
// Changed message again to report about the two possible timeouts: connection or command
// as the establishment timeout only was confusing users when the timeout was a command timeout.
}
throw new NpgsqlException(resman.GetString("Exception_ConnectionOrCommandTimeout"));
}
return ProcessBackendResponses(context);
}
catch(ThreadAbortException)
{
try
{
context.CancelRequest();
context.Close();
}
catch {}
throw;
}
}
示例9: CancelRequest
/// <summary>
/// Creates another connector and sends a cancel request through it for this connector.
/// </summary>
internal void CancelRequest()
{
var cancelConnector = new NpgsqlConnector(_settings, false);
try
{
// Get a raw connection, possibly SSL...
cancelConnector.RawOpen(cancelConnector.ConnectionTimeout*1000);
// Cancel current request.
cancelConnector.SendCancelRequest(BackEndKeyData);
}
finally
{
cancelConnector.Close();
}
}
示例10: ProcessBackendResponsesEnum
///<summary>
/// This method is responsible to handle all protocol messages sent from the backend.
/// It holds all the logic to do it.
/// To exchange data, it uses a Mediator object from which it reads/writes information
/// to handle backend requests.
/// </summary>
///
internal IEnumerable<IServerResponseObject> ProcessBackendResponsesEnum(NpgsqlConnector context)
{
try
{
// Flush buffers to the wire.
context.Stream.Flush();
// Process commandTimeout behavior.
// We will give an extra 5 seconds to context.Mediator.CommandTimeout
// because we'd prefer to receive a timeout error from PG
// than to be forced to start a new connection and send a cancel request.
// The result is that a timeout could take 5 seconds too long to occur, but if everything
// is healthy, that shouldn't happen.
if ((context.Mediator.BackendCommandTimeout > 0) && (!context.Stream.WaitAvailable(TimeSpan.FromSeconds(context.Mediator.BackendCommandTimeout + 5))))
{
// If timeout occurs when establishing the session with server then
// throw an exception instead of trying to cancel query. This helps to prevent loop as
// CancelRequest will also try to stablish a connection and sends commands.
if (!((this is NpgsqlStartupState || this is NpgsqlConnectedState)))
{
try
{
context.CancelRequest();
ProcessAndDiscardBackendResponses(context);
}
catch(Exception)
{
}
// We should have gotten an error from CancelRequest(). Whether we did or not, what we
// really have is a timeout exception, and that will be less confusing to the user than
// "operation cancelled by user" or similar, so whatever the case, that is what we'll throw.
// Changed message again to report about the two possible timeouts: connection or command
// as the establishment timeout only was confusing users when the timeout was a command timeout.
}
throw new NpgsqlException(resman.GetString("Exception_ConnectionOrCommandTimeout"));
}
switch (context.BackendProtocolVersion)
{
case ProtocolVersion.Version2:
return ProcessBackendResponses_Ver_2(context);
case ProtocolVersion.Version3:
return ProcessBackendResponses_Ver_3(context);
default:
throw new NpgsqlException(resman.GetString("Exception_UnknownProtocol"));
}
}
catch(ThreadAbortException)
{
try
{
context.CancelRequest();
context.Close();
}
catch {}
throw;
}
}
示例11: UngetPooledConnector
/// <summary>
/// Put a pooled connector into the pool queue.
/// </summary>
/// <param name="Connector">Connector to pool</param>
private void UngetPooledConnector(NpgsqlConnection Connection, NpgsqlConnector Connector)
{
ConnectorQueue Queue;
// Find the queue.
Queue = (ConnectorQueue)PooledConnectors[Connector.ConnectionString.ToString()];
if (Queue == null)
{
throw new InvalidOperationException("Internal: No connector queue found for existing connector.");
}
Connector.CertificateSelectionCallback -= Connection.CertificateSelectionCallbackDelegate;
Connector.CertificateValidationCallback -= Connection.CertificateValidationCallbackDelegate;
Connector.PrivateKeySelectionCallback -= Connection.PrivateKeySelectionCallbackDelegate;
Queue.UseCount--;
if (! Connector.IsInitialized)
{
if (Connector.Transaction != null)
{
Connector.Transaction.Cancel();
}
Connector.Close();
}
else
{
if (Connector.Transaction != null)
{
try
{
Connector.Transaction.Rollback();
}
catch {
Connector.Close()
;
}
}
}
if (Connector.State == System.Data.ConnectionState.Open)
{
// Release all plans and portals associated with this connector.
Connector.ReleasePlansPortals();
Queue.Enqueue(Connector);
}
}