Insert and Select in one Transaction: ADO - MS SQL

Forum related to version 6.5.1 (alpha) and 6.6.x (beta) of ZeosLib's DBOs

Moderators: gto, cipto_kh, EgonHugeist

Post Reply
LOTAS
Fresh Boarder
Fresh Boarder
Posts: 6
Joined: 09.06.2009, 14:57
Location: Germany
Contact:

Insert and Select in one Transaction: ADO - MS SQL

Post by LOTAS »

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

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();
2) With direct SQLs

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");
I Hope someone can help me

Johannes
LOTAS
Fresh Boarder
Fresh Boarder
Posts: 6
Joined: 09.06.2009, 14:57
Location: Germany
Contact:

Post by LOTAS »

Really noone who can help?
Johannes
seawolf
Zeos Dev Team *
Zeos Dev Team *
Posts: 385
Joined: 04.06.2008, 19:50
Contact:

Post by seawolf »

Just 2 question:

1) With StartTransaction
you need Zeos->autocommit = false; before ZEOS->StartTransaction();
Have you missed to paste it?

2) Do in both cases the same error is raised?
LOTAS
Fresh Boarder
Fresh Boarder
Posts: 6
Joined: 09.06.2009, 14:57
Location: Germany
Contact:

Post by LOTAS »

seawolf wrote:Just 2 question:

1) With StartTransaction
you need Zeos->autocommit = false; before ZEOS->StartTransaction();
Have you missed to paste it?
It's not posted as it's set in the component itself through the objectinspector. I only set it manually for the second test.

seawolf wrote:2) Do in both cases the same error is raised?
Yes, it's always the same error.
Johannes
designshouse
Fresh Boarder
Fresh Boarder
Posts: 20
Joined: 21.11.2005, 10:13
Location: Pieštany
Contact:

Post by designshouse »

try to use QyZEOS->SQL->Text->Clear before SELECT query

Code: Select all

QyZEOS->ExecSQL();
QyZEOS->Close();
QyZEOS->SQL->Text->Clear;
QyZEOS->SQL->Text = "SELECT * FROM table1";
Post Reply