Insert and Select in one Transaction: ADO - MS SQL
Posted: 12.06.2009, 13:38
Hi all,
I have a real big problem.
We use ZEOS (6.6.1 - beta) to connect via ADO with a MS SQL Server 2005. (coding with Borland C++ Builder 6).
Sometimes it is needed to work with transactions, to have the possibility to rollback when something is wrong with the recently inserted data.
For this, with BDE we have following concept:
1) Start Transaction
2) Insert into Table
3) Select from table to check if everything is OK
4a) if everything is OK -> Commit
4b) if something went wrong -> Rollback
When I try to do this with the ZEOS Components, I always get following error :
"An EOleException occured. Message: 'Multiple Recordsets are not possible with a transaction using this cursor type. Change cursor type, do a commit or close one of the recordsets'"
Does anyone knows why this happens, where I can change the cursor type or what to do?
I tried to work with direct SQLs but this also isn't working.
Codes
1) With StartTransaction
2) With direct SQLs
I Hope someone can help me
Johannes
I have a real big problem.
We use ZEOS (6.6.1 - beta) to connect via ADO with a MS SQL Server 2005. (coding with Borland C++ Builder 6).
Sometimes it is needed to work with transactions, to have the possibility to rollback when something is wrong with the recently inserted data.
For this, with BDE we have following concept:
1) Start Transaction
2) Insert into Table
3) Select from table to check if everything is OK
4a) if everything is OK -> Commit
4b) if something went wrong -> Rollback
When I try to do this with the ZEOS Components, I always get following error :
"An EOleException occured. Message: 'Multiple Recordsets are not possible with a transaction using this cursor type. Change cursor type, do a commit or close one of the recordsets'"
Does anyone knows why this happens, where I can change the cursor type or what to do?
I tried to work with direct SQLs but this also isn't working.
Codes
1) With StartTransaction
Code: Select all
ZEOS->StartTransaction();
QyZEOS->Close();
QyZEOS->SQL->Text = "INSERT INTO table (foo1, foo2) VALUES ('bar1', 'bar2')";
QyZEOS->ExecSQL();
QyZEOS->Close();
QyZEOS->SQL->Text = "SELECT * FROM table1";
DsResult->DataSet = QyZEOS;
QyZEOS->Open();
ZEOS->Rollback();
Code: Select all
ZEOS->AutoCommit = false;
int res = ZEOS->DbcConnection->CreateStatement()->ExecuteUpdate("BEGIN TRAN");
QyZEOS->Close();
QyZEOS->SQL->Text = "INSERT INTO table (foo1, foo2) VALUES ('bar1', 'bar2')";
QyZEOS->ExecSQL();
QyZEOS->Close();
QyZEOS->SQL->Text = "SELECT * FROM table1";
DsResult->DataSet = QyZEOS;
QyZEOS->Open();
res = ZEOS->DbcConnection->CreateStatement()->ExecuteUpdate("ROLLBACK");
Johannes