虽然应该没有发布Sybase连接

时间:2015-07-27 08:10:55

标签: c# connection sybase

我已经在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);
        }

提前致谢!

1 个答案:

答案 0 :(得分:0)

找到了如何执行此操作:需要指定ConnectionIdleTimeout parameter in the connection string