Unix Technical Forum

Transactions in ODBC

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 ...


Go Back   Unix Technical Forum > Database Server Software > Microsoft SQL Server > MS SQL ODBC

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-27-2008, 08:15 PM
Mikael Lindblom
 
Posts: n/a
Default Transactions in ODBC

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




Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-27-2008, 08:17 PM
Brannon Jones
 
Posts: n/a
Default Re: Transactions in ODBC

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
>
>
>
>



Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 08:41 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com