简体   繁体   English

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

[英]How to close a connection with a firebird database

I'm developing a project using asp.net c# webforms framework 4.5, and I did a connection test on Firebird database, but when I close this connection it isn't closing, I used the following code to do it:我正在使用 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);
    }

}

I have already used the .Close() and .Dispose() command but it didn't work.我已经使用了.Close().Dispose()命令,但它没有用。

When I did this debugging I realized that when it pass by .Open() command it opens the connection, that is alright.当我做这个调试时,我意识到当它通过.Open()命令时,它会打开连接,没关系。 But when it pass by .Close() command the connection is still open on database.但是当它通过.Close()命令时,连接仍然在数据库上打开。

To know the number of connections opened on database I'm using the following command:要知道在数据库上打开的连接数,我使用以下命令:

select * FROM MON$ATTACHMENTS

The Firebird .NET provider has a built-in connection pool and it is enabled by default. Firebird .NET 提供程序有一个内置的连接池,默认情况下它是启用的。 You can add Pooling=false to the connection string to disable it.您可以将Pooling=false添加到连接字符串以禁用它。 However in a lot of cases a connection pool is a good thing (it saves the time of having to open a connection), so make sure you really need to disable it.然而,在很多情况下,连接池是一件好事(它可以节省必须打开连接的时间),因此请确保您确实需要禁用它。

Calling FbConnection.ClearPool(connection) or FbConnection.ClearAllPools() should close currently open connections in the pool.调用FbConnection.ClearPool(connection)FbConnection.ClearAllPools()应该关闭池中当前打开的连接。

Also make sure you start a new transaction when querying MON$ATTACHMENTS .还要确保在查询MON$ATTACHMENTS时开始一个新事务。 The content of monitoring tables is 'frozen' inside a single transaction.监控表的内容在单个事务中“冻结”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM