vinmak
asked on
ODBC transaction issue with Visual C++
I'm having a problem trying to use ODBC with transactions on an application I've inherited. The application is already using ODBC throughout (a re-write is currently not possible for those who do not think I should not be using ODBC).
I'm trying to use the "SQLSetConnectAttr()" function to set the auto-commit/manual-commit modes. However
if I do the following for example:
SQLSetConnectAttr(m_hDBC, SQL_ATTR_AUTOCOMMIT, SQL_AUTOCOMMIT_OFF, SQL_IS_UINTEGER))
Compilation fails with the compiler complaining that it is expecting a "void *" as the third parameter
even though the above is exactly what is shown in various literature.
I thus do the following:
UINT value;
value = SQL_AUTOCOMMIT_OFF;
SQLSetConnectAttr(m_hDBC, SQL_ATTR_AUTOCOMMIT, &value, SQL_IS_POINTER);
The above now compiles without any problems. However when I run my application, the above returns an
"SQL_ERROR" with the following error message:
"[Microsoft][ODBC Driver Manager]Invalid argument value"
What am I doing wrong? I've tried SQL_IS_POINTER, SQL_IS_UINTEGER, and NULL as the last (fourth) argument and still get the above error message. Tracing the code, the constants SQL_ATTR_AUTOCOMMIT, SQL_AUTOCOMMIT_OFF, SQL_AUTOCOMMIT_ON, SQL_IS_POINTER, and SQL_IS_UINTEGER have values of 102, 0, 1, -4, and -5 respectively.
Other v3+ ODBC functions (such as "SQLGetDiagRec()" are working properly in the application.
I've ended up having to resort to using the deprecated function "SQLSetConnectOption()" to set the auto-commit/manual-commit modes.
Additional Info:
OS: Windows NT v4.0
Microsoft Visual C++ v6.0
DB: MS SQL Server 7.0
ODBC driver: SQL Server v3.70.08.20
I'm trying to use the "SQLSetConnectAttr()" function to set the auto-commit/manual-commit modes. However
if I do the following for example:
SQLSetConnectAttr(m_hDBC, SQL_ATTR_AUTOCOMMIT, SQL_AUTOCOMMIT_OFF, SQL_IS_UINTEGER))
Compilation fails with the compiler complaining that it is expecting a "void *" as the third parameter
even though the above is exactly what is shown in various literature.
I thus do the following:
UINT value;
value = SQL_AUTOCOMMIT_OFF;
SQLSetConnectAttr(m_hDBC, SQL_ATTR_AUTOCOMMIT, &value, SQL_IS_POINTER);
The above now compiles without any problems. However when I run my application, the above returns an
"SQL_ERROR" with the following error message:
"[Microsoft][ODBC Driver Manager]Invalid argument value"
What am I doing wrong? I've tried SQL_IS_POINTER, SQL_IS_UINTEGER, and NULL as the last (fourth) argument and still get the above error message. Tracing the code, the constants SQL_ATTR_AUTOCOMMIT, SQL_AUTOCOMMIT_OFF, SQL_AUTOCOMMIT_ON, SQL_IS_POINTER, and SQL_IS_UINTEGER have values of 102, 0, 1, -4, and -5 respectively.
Other v3+ ODBC functions (such as "SQLGetDiagRec()" are working properly in the application.
I've ended up having to resort to using the deprecated function "SQLSetConnectOption()" to set the auto-commit/manual-commit modes.
Additional Info:
OS: Windows NT v4.0
Microsoft Visual C++ v6.0
DB: MS SQL Server 7.0
ODBC driver: SQL Server v3.70.08.20
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
i know, i have previous trouble where functions expect various data types through a void * pointer, socket calls to name only one
ASKER
Thanks for your input...it worked! I'm suprised none of the examples in the documention/literature I read showed it the way you did.