problems with OdbcDataReaders

  • Thread starter Thread starter José Achig
  • Start date Start date
J

José Achig

Hello, I have problems with OdbcDataReaders, I always recieve these errors:
ExecuteReader requires an open and available Connection. The connections
current state is Open,

Executing or There is already an open DataReader associated with this
Connection which must be

closed first.

The function that use DataReaders is the following:


This function is called every time one application is going to be opened

ArrayList *MonitorApps::CListaTareas::ObtieneProcsNoPermitidos()
{

if (hayConexion) {

/* almacena las aplicaciones que están permitidas */
OdbcDataReader *DtRdrProcsNopermts;
arrProcsNoPermts->Clear();

/* bloque de código que revisa si el proceso está permitido */
sentencia = "SELECT nombre FROM procesorestringido";

if (DtRdrProcsNopermts)
if (!DtRdrProcsNopermts->IsClosed)
DtRdrProcsNopermts->Close();

DtRdrProcsNopermts = interBD->EjecutarConsulta(sentencia, nombreMaquina);

// Always call Read before accessing data.
while (DtRdrProcsNopermts->Read())
arrProcsNoPermts->Add(DtRdrProcsNopermts->GetString(0));

// always call Close when done reading.
DtRdrProcsNopermts->Close();
DtRdrProcsNopermts=NULL;

return arrProcsNoPermts;
}

}



OdbcDataReader *ObjetoRemoto::metodos_BD::EjecutarConsulta(String *consulta,
String *nomMaquina)
{

try {
/* abre la conexión a la BD */
//conexion->Open();
OdbcCommand *inst = new OdbcCommand(consulta, conexion);

/*Ejecuta la sentencia*/
return inst->ExecuteReader();
}
catch(Exception *ex){

InsertaMensajesError(nomMaquina, ex->Message->ToString(),

"ObjetoRemoto::metodosBD::EjecutarConsulta", 80);
InsertaMensajesError(nomMaquina, ex->Message->ToString(), consulta, 80);

}

}

I always try to close the DataReader before to use it, but always too I get
the errors that I tell you.

Please give me an advice

Thank you
 
This happens if you are attempting to use a DataReader and or DbCommand
before closing the DataReader.
Make sure you close each DataReader when you are done using it. If you need
to have multiple DataReaders at the same time make multiple DBCommands and
DBConnections
 
Back
Top