0
I’m not sure what the reason for the error I’m having but it seems that it is something related to open connections in the bank, where error is occurring if the application tries to create more connections than the limit. I believe this is the reason for the mistake.
I am closing all Connection I open for an interaction (Insert/update/delete/select).
I’ve read a few topics about this here on Stack Overflow, but no C# based that solved this problem.
Follow my connection code db
and an interaction as an example:
Class for Connection:
public class ClassConexao
{
public static MySqlConnection ObterConexao()
{
MySqlConnection conectar = new MySqlConnection("server=ENDEREÇO; database=NOME; Uid=USER; pwd=****");
conectar.Open();
return conectar;
}
}
Interacting :
try
{ //ABRINDO CONEXAO01
MySqlConnection conexão01= ClassConexao.ObterConexao();
MySqlCommand _comandoSel = new MySqlCommand(String.Format("SELECT Column1, Column2 FROM tableA WHERE Column1 = " + "500" + ""), conexão01);
MySqlDataReader 01_reader = _comando01.ExecuteReader();
Sel_reader.Read();
textbox1.Text = 01_reader.GetString(0);
textbox2.Text = 01_reader.GetString(1);
//FECHANDO CONEXAO01
conexão01.Close();
catch (Exception error)
{
MessageBox.Show(String.Format("Algo está errado com a operação! {0}", error.Message));
return;
}
Error message returned from:
Is there any way to increase this limit? Or other solution that does not limit connections?
Give a Dispose on the connection after Close and see if it resolves.
– Ricardo
@Ricardo How do I use Dispose ? connection01.Dispose(); ?
– Maurício Sanches
Look at my answer, I believe this can solve.
– Ricardo