I just started a new job and I'm dealing with a lot of code for websites that I did not write.
This error keeps happening in one of the websites but not all the time, sometimes the website works just fine and goes down for a few minutes or sometimes it goes down for hours:
ExecuteReader requires an open and available Connection. The connection's current state is open.
I have been checking and in all functions there is a function call Abrir() and Cerrar():
private void Abrir(){
try
{
conexion.Open();
}
catch (InvalidOperationException)
{
Cerrar();
}
catch (DbException)
{
throw new AccesoDatosExcepcion("No se pudo abrir la conexion con la BD");
}
}
private void Cerrar()
{
try
{
conexion.Close();
}
catch (DbException)
{
throw new AccesoDatosExcepcion("No se pudo cerrar la conexion con la BD");
}
}
These functions are everywhere you need to open or close the connection so I don't know why it tells me I need an open connection.
Thanks for the help.