>Hello,
>I am having a problem with Microsoft's ODBC driver for Windows NT.
>SQLConnect works fine until I try to debug my application with developer
>studio. While debugging, SQLConnect causes a general protection fault. I
>can't debug my application!!! I don't know whether this is a bug in
>SQLConnect or if I'm just using it incorrectly.
>Any help would be appreciated
>Thanks
ig: Try this simple test:
#include <afx.h>
#include <afxdb.h>
#include <stdio.h>
#define RC_FAILURE(x) ((x) == SQL_ERROR || \
(x) == SQL_INVALID_HANDLE)
#define RC_SUCCESS(x) ((x) == SQL_SUCCESS || \
(x) == SQL_SUCCESS_WITH_INFO)
// for general exception handling
class clError
{
public:
clError(const CString& msg);
~clError();
const CString& get_msg() const;
operator const CString&() const;
private:
CString errMsg_;
private:
void operator,(const clError&);
void operator&();
} ;
int
main(int argc, _TCHAR* argv[])
{
_TCHAR* usage = _T("\nUsage: ./program dsn uid <pwd>\n");
if (argc < 3 || argc > 4)
{
_fputts(usage, stderr);
return 1;
}
try
{
RETCODE rc;
HENV henv;
HDBC hdbc;
HSTMT hstmt;
rc = SQLAllocEnv(&henv);
if (RC_FAILURE(rc))
throw clError(_T("Error: SQLAllocEnv()"));
rc = SQLAllocConnect(henv, &hdbc);
if (RC_FAILURE(rc))
throw clError(_T("Error: SQLAllocConnect()"));
rc = SQLConnect(hdbc,
(_TUCHAR*)argv[2], SQL_NTS,
(_TUCHAR*)argv[3], SQL_NTS,
argc == 5 ? (_TUCHAR*)argv[4] : NULL, SQL_NTS);
if (RC_FAILURE(rc))
throw clError(_T("Error: SQLConnect()"));
rc = SQLAllocStmt(hdbc, &hstmt);
if (RC_FAILURE(rc))
throw clError(_T("Error: SQLAllocStmt()"));
_fputts(_T("Successful ODBC Init.\n"), stdout);
SQLFreeStmt(hstmt, SQL_DROP);
SQLDisconnect(hdbc);
SQLFreeConnect(hdbc);
SQLFreeEnv(henv);
}
catch (clError& err)
{
_ftprintf(stderr, _T("%s\n"), err.get_msg());
return 1;
}
return 0;
}
//# ig