Timeout while Getting a Connection from pool

Asked

Viewed 827 times

0

You’re making this mistake. I’m using postgres

Erro ao buscar servidor por id: Timeout while getting a connection from pool.
A first chance exception of type 'System.Exception' occurred in BackupDAO.dll

Method

public Servidor buscarPorID(int id)
    {
        try
        {
            DAOFactoryNuvem dao = new DAOFactoryNuvem();
            conexao = dao.CriaConexao();

            String sql = "select * from servidor where id = "+id;
            NpgsqlCommand sqlCon = new NpgsqlCommand(@sql, conexao);
            conexao.Open();

            NpgsqlDataReader drCon;

            drCon = sqlCon.ExecuteReader();

            while (drCon.Read())
            {
                Servidor servidor = new Servidor(Convert.ToInt32(drCon[0]), drCon[1].ToString(), drCon[2].ToString());
                drCon.Close();

                return servidor;
            }

            Servidor servidor1 = new Servidor(0, "", "");

            conexao.Dispose();
            return servidor1;
        }
        catch (Exception erro)
        {
            Console.WriteLine("Erro ao buscar servidor por id: " + erro.Message);
            throw erro;
        }
        finally
        {
            conexao.Clone();
        }
    }

1 answer

4


Hello,

Add to your connection string and see if it worked.

Pooling=false;

I would guess that there are many open connections, but I looked that Voce da um Ispose(); so it shouldn’t be that.

  • But there are many more methods in other Daos that are called at the same time, I only sent this one so as not to send everyone, because I thought that Disposis could be in the wrong place. I’ll try that there.

  • Try to give each a Dispose() . I would recommend using only 1 Connection() and closing it. Better than opening and closing 1000 times.If possible post the rest of the code, the other Daos

  • A connectionby DAO in case?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.