Firebird C # create a single connection to the database

0

I need to create in my application only one connection using fbconnection that will be shared by every application.

I performed this procedure as follows.

I created a static class that gives me the connection to DB:

static class Conexao
{


    private static String strConn = Properties.Settings.Default.caminhoFbConnection;
    private static FbConnection conn = null;


    public static void Conection()
    {

    }

    public static FbConnection getConnection()
    {
        try
        {

            if (conn == null)
            {
                conn = new FbConnection(strConn);
                conn.Open();
                return conn;
            }
            else
            {
                if (conn.State == System.Data.ConnectionState.Open)
                {
                    return conn;
                }
                else
                {
                    FbConnection.ClearAllPools();
                    conn = new FbConnection(strConn);
                    conn.Open();
                    return conn;
                }
            }
        }
        catch (Exception excep)
        {
            MessageBox.Show("Erro - " + excep.Message);
            return null;
        }
    }
}

And every time I need a connection I simply call the function Conexao.getConnection();

My question is this: do you have any problems using and or creating the connection in a static way and using it during the whole program execution? Or can it overload and crash in the middle of the run?

    
asked by anonymous 17.09.2015 / 02:42

0 answers