This is a discussion on Transactions in ODBC within the MS SQL ODBC forums, part of the Microsoft SQL Server category; --> I have an app running using the old MFC CDatabase classes to work against a SQL2000 database. The app ...
| |||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| I have an app running using the old MFC CDatabase classes to work against a SQL2000 database. The app makes use of a lot of stored procedures, which I somtimes executes by using the ExecuteSQL method of the CDatabase class and somtimes together with a CRecordset derivate. I use the {CALL sp()} syntax. The server is setup using IMPLICIT TRANSACTIONS OFF which leave me with autocommitted transactions. This means, I belive, that every successful statement is committed. Many of my procedures does a number of SELECT to find out what UPDATES to do and then finally does the updates. I want to make sure that all of the updates are made correctly, but not make the first selects part of the transaction. What is the preferred way to do this? In MSDN you can read the following " ODBC applications should not use Transact-SQL transaction statements (such as BEGIN TRANSACTION, COMMIT TRANSACTION, ROLLBACK TRANSACTION) because this can result in indeterminate behavior in the driver. An ODBC application should either: Run in autocommit mode and not use any transaction management functions or statements. -or- Run in manual-commit mode and use the ODBC SQLEndTran function to either commit or roll back transactions. " Please help me out here Mikael |
| ||||
| If you're using straight ODBC, you want to use SQLSetConnectAttr() to turn auto commit mode off. The next statement you send to the server (via SQLExecute/SQLExecDirect) will begin a transaction. When you are finished with the transaction, you use SQLTransact() to commit the transaction. A quick look at the CDatabase docs shows a BeginTrans() method. Use that to begin a transaction and CommitTrans() to commit it when you're done. "Mikael Lindblom" <NoSpam_mlm@idabwamac.com> wrote in message news:075b01c3572f$e6b64450$a501280a@phx.gbl... > I have an app running using the old MFC CDatabase classes > to work against a SQL2000 database. > > The app makes use of a lot of stored procedures, which I > somtimes executes by using the ExecuteSQL method of the > CDatabase class and somtimes together with a CRecordset > derivate. I use the {CALL sp()} syntax. > > The server is setup using IMPLICIT TRANSACTIONS OFF which > leave me with autocommitted transactions. This means, I > belive, that every successful statement is committed. > > Many of my procedures does a number of SELECT to find out > what UPDATES to do and then finally does the updates. I > want to make sure that all of the updates are made > correctly, but not make the first selects part of the > transaction. > > What is the preferred way to do this? > > In MSDN you can read the following > > " > ODBC applications should not use Transact-SQL transaction > statements (such as BEGIN TRANSACTION, COMMIT > TRANSACTION, ROLLBACK TRANSACTION) because this can > result in indeterminate behavior in the driver. An ODBC > application should either: > > Run in autocommit mode and not use any transaction > management functions or statements. > -or- > > Run in manual-commit mode and use the ODBC SQLEndTran > function to either commit or roll back transactions. " > > Please help me out here > > Mikael > > > > |