我已经在Sybase中构建了自己的连接池,因为我无法弄清楚Sybase是否有人为C#工作。
工作正常。但是无法释放连接(尽管我关闭并处理)。你对此有所了解吗?
停止连接:
protected void StopDbConnections()
{
var count = _dbConnectionPool.Count;
while (_dbConnectionPool.Count != 0)
{
var connection = _dbConnectionPool[0];
CloseDbConnection(connection);
_dbConnectionPool.Remove(connection);
}
}
private void CloseDbConnection(AseConnection connectionToClose)
{
if (connectionToClose != null)
{
connectionToClose.Close();
connectionToClose.Dispose();
}
}
如果需要,连接池定义:
protected void StartDbConnections(int numberOfConnections = 1)
{
for (var i = 0; i < numberOfConnections; i++)
{
AseConnection connection = null;
if (_dbConnectionPool.Count > i)
{
connection = _dbConnectionPool[i];
if (connection != null && connection.State == ConnectionState.Open)
{
StopDbConnection(connection);
}
}
connection = InitializeConnection();
_dbConnectionPool.Add(connection);
}
提前致谢!