Discussion:
Error reading data connection
(too old to reply)
David
2005-06-22 19:19:34 UTC
Permalink
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
David
2005-06-23 07:25:46 UTC
Permalink
Post by David
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.
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;
}
....
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
Without threads do not work fine yet

Help!!

Thanks
Wayne Niddery [TeamB]
2005-06-23 16:17:03 UTC
Permalink
Post by David
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).
Which version of InterBase, and which version of the IBX components are you
using?

With InterBase 7.x, you *should* be able to share a single TIBDatabase among
threads, however even then access between threads is going to be serialized.
So you are still better off to allow each thread to have its own TIBDatabase
as well as TIBTransaction. For InterBase older than 7.x, you *must* have
separate TIBDatabase components for each thread.
--
Wayne Niddery - Logic Fundamentals, Inc. (www.logicfundamentals.com)
RADBooks: http://www.logicfundamentals.com/RADBooks.html
"We've all heard that a million monkeys banging on a million
typewriters will eventually reproduce the entire works of Shakespeare.
Now, thanks to the Internet, we know this is not true." — Robert
Wilensky
David
2005-06-23 17:02:51 UTC
Permalink
Post by Wayne Niddery [TeamB]
Post by David
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).
Which version of InterBase, and which version of the IBX components are you
using?
With InterBase 7.x, you *should* be able to share a single TIBDatabase among
threads, however even then access between threads is going to be serialized.
So you are still better off to allow each thread to have its own TIBDatabase
as well as TIBTransaction. For InterBase older than 7.x, you *must* have
separate TIBDatabase components for each thread.
--
Wayne Niddery - Logic Fundamentals, Inc. (www.logicfundamentals.com)
RADBooks: http://www.logicfundamentals.com/RADBooks.html
"We've all heard that a million monkeys banging on a million
typewriters will eventually reproduce the entire works of Shakespeare.
Now, thanks to the Internet, we know this is not true." — Robert
Wilensky
I am using IB 6.0.1.6 and IBX 4.5.2 .
I guess that is the problem. Is not it?

I have IB 7.1, Can my problem be solved whith this version?

Thanks
Wayne Niddery [TeamB]
2005-06-24 22:50:36 UTC
Permalink
Post by David
I am using IB 6.0.1.6 and IBX 4.5.2 .
I guess that is the problem. Is not it?
Yes. it is guaranteed to cause problems. The issue is not IBX, it is the
InterBase client (gds32.dll) that is not thread safe on one connection in
versions prior to 7.x.
Post by David
I have IB 7.1, Can my problem be solved whith this version?
Yes, but if the goal is performance then I would still give each thread its
own TIBDatabase, and if you do that then you could use either version of
InterBase safely with threads.
--
Wayne Niddery - Logic Fundamentals, Inc. (www.logicfundamentals.com)
RADBooks: http://www.logicfundamentals.com/RADBooks.html
"We've all heard that a million monkeys banging on a million
typewriters will eventually reproduce the entire works of Shakespeare.
Now, thanks to the Internet, we know this is not true." — Robert
Wilensky
Loading...