David
2005-06-22 19:19:34 UTC
Hi,
I need some help.
I have a class that encapsulates the DB connection. Each class instance has its transaction (TIBTransaction) (All instances shares a TIBDatabase instance that is always connected).
When I use several threads with some connections, IBExpress throws the Error
-Error reading data from the connection
When I do not use threads work fine.
The code of this class is:
ConexionIB::~ConexionIB(){
ELIMINARPTR(transaction);
// }
}
ConexionIB::ConexionIB(TIBDatabase *database){
this->database = database;
transaction = NULL;
}
//---------------------------------------------------------------------------
TIBTransaction * ConexionIB::getTransaction(){
return transaction;
}
//---------------------------------------------------------------------------
TIBDatabase * ConexionIB::getDatabase(){ return database; }
//---------------------------------------------------------------------------
void ConexionIB::rollback(){
if(transaction == NULL)
return;
else{
if(transaction->InTransaction){
transaction->Rollback();
}
delete transaction;
transaction = NULL;
}
}
//---------------------------------------------------------------------------
void ConexionIB::commit(){
if(transaction == NULL)
return;
if(transaction->InTransaction){
transaction->Commit();
}
delete transaction;
transaction = NULL;
}
//---------------------------------------------------------------------------
void ConexionIB::iniciaTransaccion(){
transaction = new TIBTransaction(NULL);
transaction->DefaultDatabase = database;
int i = database->AddTransaction(transaction);
transaction->StartTransaction();
}
//---------------------------------------------------------------------------
bool ConexionIB::estaConectada(){
bool resultado;
try{
database->Open();
resultado = true;
} catch (Exception &){
resultado = false;
}
return resultado;
}
//---------------------------------------------------------------------------
void ConexionIB::conectar(){
database->Connected = true;
}
//---------------------------------------------------------------------------
void ConexionIB::desconectar(){
database->Connected = false;
}
the code of a DB access is always like:
....
connection->iniciaTransaccion() //Start transaction
....
TIBSQL *query=NULL;
try{
try{
query = new TIBSQL(NULL);
query->Transaction = connection->getTransaction();
query->SQL->Clear();
query->SQL->Add(...);
....
query->ExecQuery();
....
}catch(Exception &e){
throw ExcepcionErrorInterno(e);
}
}__finally{
if(query!=NULL){
delete query;
query=NULL;
}
}
....
More BD access
....
connection->commit() // or rollback
delete connection;
Why IBExpress throws this errors when I use threads and simultaneous transactions?
Thanks
I need some help.
I have a class that encapsulates the DB connection. Each class instance has its transaction (TIBTransaction) (All instances shares a TIBDatabase instance that is always connected).
When I use several threads with some connections, IBExpress throws the Error
-Error reading data from the connection
When I do not use threads work fine.
The code of this class is:
ConexionIB::~ConexionIB(){
ELIMINARPTR(transaction);
// }
}
ConexionIB::ConexionIB(TIBDatabase *database){
this->database = database;
transaction = NULL;
}
//---------------------------------------------------------------------------
TIBTransaction * ConexionIB::getTransaction(){
return transaction;
}
//---------------------------------------------------------------------------
TIBDatabase * ConexionIB::getDatabase(){ return database; }
//---------------------------------------------------------------------------
void ConexionIB::rollback(){
if(transaction == NULL)
return;
else{
if(transaction->InTransaction){
transaction->Rollback();
}
delete transaction;
transaction = NULL;
}
}
//---------------------------------------------------------------------------
void ConexionIB::commit(){
if(transaction == NULL)
return;
if(transaction->InTransaction){
transaction->Commit();
}
delete transaction;
transaction = NULL;
}
//---------------------------------------------------------------------------
void ConexionIB::iniciaTransaccion(){
transaction = new TIBTransaction(NULL);
transaction->DefaultDatabase = database;
int i = database->AddTransaction(transaction);
transaction->StartTransaction();
}
//---------------------------------------------------------------------------
bool ConexionIB::estaConectada(){
bool resultado;
try{
database->Open();
resultado = true;
} catch (Exception &){
resultado = false;
}
return resultado;
}
//---------------------------------------------------------------------------
void ConexionIB::conectar(){
database->Connected = true;
}
//---------------------------------------------------------------------------
void ConexionIB::desconectar(){
database->Connected = false;
}
the code of a DB access is always like:
....
connection->iniciaTransaccion() //Start transaction
....
TIBSQL *query=NULL;
try{
try{
query = new TIBSQL(NULL);
query->Transaction = connection->getTransaction();
query->SQL->Clear();
query->SQL->Add(...);
....
query->ExecQuery();
....
}catch(Exception &e){
throw ExcepcionErrorInterno(e);
}
}__finally{
if(query!=NULL){
delete query;
query=NULL;
}
}
....
More BD access
....
connection->commit() // or rollback
delete connection;
Why IBExpress throws this errors when I use threads and simultaneous transactions?
Thanks