如何关闭与firebird数据库的连接

Luc*_*usa 1 c# database asp.net firebird webforms

我正在使用asp.net c#webforms framework 4.5开发一个项目,并且我在Firebird数据库上进行了连接测试,但当我关闭此连接时它没有关闭,我使用以下代码来执行此操作:

string conDDNS;
FbConnection conexaoDDNS;

protected void Abrir_Fechar_Click(object sender, EventArgs e)
{
    try
    {
        this.conDDNS = "DRIVER=InterBase/Firebird(r) driver;User=SYSDBA;Password=masterkey;Database=localhost:C:/AdCom/ADCOM.FDB";

        this.conexaoDDNS = new FbConnection(conDDNS);
        this.conexaoDDNS.Open();
        ListItem item = new ListItem("Conexão aberta");
        ListBox1.Items.Add(item);

        this.conexaoDDNS.Dispose();
        this.conexaoDDNS.Close();
        ListItem item2 = new ListItem("Conexão fechada");
        ListBox1.Items.Add(item2);

    }
    catch (Exception erro)
    {
        ListItem item = new ListItem(erro.ToString());
        ListBox1.Items.Add(item);
    }

}
Run Code Online (Sandbox Code Playgroud)

我已经使用了.Close().Dispose()命令,但它没有用.

当我进行这个调试时,我意识到当它通过.Open()命令传递时它会打开连接,这没关系.但是当它通过.Close()命令时,连接仍然在数据库上打开.

要知道在数据库上打开的连接数,我使用以下命令:

select * FROM MON$ATTACHMENTS
Run Code Online (Sandbox Code Playgroud)

Mar*_*eel 6

Firebird .NET提供程序具有内置连接池,默认情况下已启用.您可以添加Pooling=false到连接字符串以禁用它.但是在很多情况下,连接池是一件好事(它节省了必须打开连接的时间),因此请确保您确实需要禁用它.

调用FbConnection.ClearPool(connection)FbConnection.ClearAllPools()应关闭池中当前打开的连接.

还要确保在查询时启动新事务MON$ATTACHMENTS.监控表的内容在单个事务中被"冻结".