如何关闭与Firebird数据库的连接 [英] How to close a connection with a firebird database

查看:66
本文介绍了如何关闭与Firebird数据库的连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用asp.net c#webforms框架4.5开发项目,并且在Firebird数据库上进行了连接测试,但是当我关闭此连接时,我并没有使用下面的代码来进行连接:/p>

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:

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);
    }

}

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

I have already used the .Close() and .Dispose() command but it didn't work.

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

When I did this debugging I realized that when it pass by .Open()command it opens the connection, that is alright. But when it pass by .Close() command the connection is still open on database.

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

To know the number of connections opened on database I'm using the following command:

select * FROM MON$ATTACHMENTS

推荐答案

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

The Firebird .NET provider has a built-in connection pool and it is enabled by default. You can add Pooling=false to the connection string to disable it. 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.

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

Calling FbConnection.ClearPool(connection) or FbConnection.ClearAllPools() should close currently open connections in the pool.

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

Also make sure you start a new transaction when querying MON$ATTACHMENTS. The content of monitoring tables is 'frozen' inside a single transaction.

这篇关于如何关闭与Firebird数据库的连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆