How to close connection to the Firebird database

3

I'm trying to create a web application in ASP.NET C #, but I'm not sure how to do it. p>

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 tried to use only the command .Close() but it did not work, I tried to use .Close() and .Dispose() but it did not work either.

When I did this, I realized that by passing the command .Open() it opens the connection normally, but when it passes the .Close() command and the .Dispose() the connection is still open in firebird.

To find out the number of open connections in firebird I am using the command select * FROM MON$ATTACHMENTS

    
asked by anonymous 12.02.2016 / 19:49

2 answers

1

According to the principle of unique functionality, I suggest you separate in different methods.

public class ConnectionFirebird
{
    private static FbConnection AbreBD()
    {
        FbConnection ConexaoBanco = new FbConnection();
        try
        {
            string _conn;
            _conn = "User=SYSDBA;Password=masterkey";
            _conn += ";Database=C:\(path_database)";
            _conn += ";Port=3050;Dialect=3;Charset=NONE;Role=;Connection lifetime=0;";
            _conn += "Connection timeout=7;Pooling=True;Packet Size=8192;Server Type=0";
            ConexaoBanco.ConnectionString = _conn;
            ConexaoBanco.Open();

            return ConexaoBanco;
        }
        catch (Exception erro)
        {
            MessageBox.Show(String.Format("Falha na Tentativa de Acesso a Base de Dados Informada);
            return ConexaoBanco;
        }
    }

    public static bool TestaConn()
    {
        FbConnection Conexao;
        bool Retorno = false;

        Conexao = AbreBD();
        Retorno = false;
        if (Conexao.State == ConnectionState.Open)
        {
            Conexao.Close();
            Retorno = true;
        }
        return Retorno;
    }
    private static void FechaBanco(IDbConnection Conn)
    {
        // Verifica se a conexão do banco de dados está aberta
        if (Conn.State == ConnectionState.Open)
        {
            Conn.Close();
        }
    }
}

* change (path_database)

    
04.01.2017 / 13:54
-2

My friend recommend reading the code: Connecting with Firebase

I also believe that using the code block ( using ) might solve your problem.

Hugs.

    
12.02.2016 / 20:47