How to close a connection with a firebird database

*爱你&永不变心* 提交于 2020-12-26 20:05:36

问题


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

}

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

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

回答1:


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.

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

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



来源:https://stackoverflow.com/questions/35408912/how-to-close-a-connection-with-a-firebird-database

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!