Ms SQL server, ODBC and vc++ : how to do rollback ? 
Author Message
 Ms SQL server, ODBC and vc++ : how to do rollback ?

Hi,

I'm a beginner with SQL and i'm doing a c++ code to access a Ms SQL
database with ODBC protocol.

I open my database like this :
sqlResult = SQLSetConnectAttr( hdbc, SQL_AUTOCOMMIT_OFF, sSqlCmde,
sizeof(sSqlCmde) );

The SQL_AUTOCOMMIT_OFF parameter is really important for me, because I
want  to be able to cancel a list of many SQL commands if something goes
wrong when i do INSERT commands !

I execute INSERT commands like this :
SQLPrepare( hstmt, ( UCHAR *)sSqlCmde ,SQL_NTS );
SQLExecute( hstmt );

And finaly :
SQLEndTran( SQL_HANDLE_DBC, pBDD->hdbc, SQL_COMMIT );
if I accept the transaction, or
SQLEndTran( SQL_HANDLE_DBC, pBDD->hdbc, SQL_ROLLBACK );
If I want to cancel the transaction.

Unfortunately, this doesn't work as I'd like to : All command are auto
commited, and the SQL_ROOLBACK doesn't cancel the commands :( This causes
bad values inserted on my database, witch is really boring !

I'm sure I didn't understood a subtle with the SQLEndTran API, but what ?

So maybe somebody could give me some pointers to correctly impelement
COMMIT and ROLLBACK.

Many thanks

--
Eric Belhomme



Sat, 30 Oct 2004 16:37:03 GMT  
 Ms SQL server, ODBC and vc++ : how to do rollback ?
Hi Eric,
Use ADO to access MS SQL databae with ODBC

Vijay


Quote:
> Hi,

> I'm a beginner with SQL and i'm doing a c++ code to access a Ms SQL
> database with ODBC protocol.

> I open my database like this :
> sqlResult = SQLSetConnectAttr( hdbc, SQL_AUTOCOMMIT_OFF, sSqlCmde,
> sizeof(sSqlCmde) );

> The SQL_AUTOCOMMIT_OFF parameter is really important for me, because I
> want  to be able to cancel a list of many SQL commands if something goes
> wrong when i do INSERT commands !

> I execute INSERT commands like this :
> SQLPrepare( hstmt, ( UCHAR *)sSqlCmde ,SQL_NTS );
> SQLExecute( hstmt );

> And finaly :
> SQLEndTran( SQL_HANDLE_DBC, pBDD->hdbc, SQL_COMMIT );
> if I accept the transaction, or
> SQLEndTran( SQL_HANDLE_DBC, pBDD->hdbc, SQL_ROLLBACK );
> If I want to cancel the transaction.

> Unfortunately, this doesn't work as I'd like to : All command are auto
> commited, and the SQL_ROOLBACK doesn't cancel the commands :( This causes
> bad values inserted on my database, witch is really boring !

> I'm sure I didn't understood a subtle with the SQLEndTran API, but what ?

> So maybe somebody could give me some pointers to correctly impelement
> COMMIT and ROLLBACK.

> Many thanks

> --
> Eric Belhomme



Sun, 05 Dec 2004 18:10:04 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Keeping Cursor Open After a RollBack (MFC,ODBC,SQL Server 7.0)

2. Perform SQL statement in VC++ against MS SQL Server 7.0

3. ODBC and MS SQL Server 6.5

4. Visual C++, ODBC and MS SQL Server 7.0

5. Visual C++, ODBC, and MS SQL Server 7.0

6. Visual C++, ODBC and MS SQL Server 7.0

7. Preserving writable server cursor after rollback (7.0, vc++, CDatabase/CRecordset)

8. How do I use SQL server in VC without ODBC

9. Invoking MS SQL Server Procedures from VC++

10. VC++ Enterprise boxed with MS SQL Server, Developer Edition 6.5

11. Crystal Reports: SQL Server & MS VC++ 6.0

12. PROBLEM: Accessing SQL SERVER 6.5 from 16 bit ODBC Application (VC++ 1.5)

 

 
Powered by phpBB® Forum Software