ODBC connection with VC6
by BMiuritan · in Torque Game Engine · 01/03/2006 (6:55 am) · 1 replies
Hi all,
I'm trying connect TGE 1.4 demo application to ODBC by my own class like this:
\\------------------------------
#include "stdio.h"
#include "string.h"
#include "windows.h"
#include "sql.h"
#include "sqlext.h"
#include "sqltypes.h"
#include "odbcss.h"
SQLHENV henv = SQL_NULL_HENV;
SQLHDBC hdbc1 = SQL_NULL_HDBC;
SQLHSTMT hstmt1 = SQL_NULL_HSTMT;
IMPLEMENT_CONOBJECT(SQLObject);
void SQLObject::initDBServer()
{
RETCODE retcode;
char *szDSN = "MyDSN", *szUID = "sa", *szAuthStr = "sa";
// Allocate the ODBC Environment and save handle.
retcode = SQLAllocHandle (SQL_HANDLE_ENV, NULL, &henv);
// Notify ODBC that this is an ODBC 3.0 application.
retcode = SQLSetEnvAttr(henv, SQL_ATTR_ODBC_VERSION,
(SQLPOINTER)SQL_OV_ODBC3, SQL_IS_INTEGER);
// Allocate an ODBC connection handle and connect.
retcode = SQLAllocHandle(SQL_HANDLE_DBC, henv, &hdbc1);
retcode = SQLConnect(hdbc1, szDSN, (SWORD)strlen(szDSN),
szUID, (SWORD)strlen(szUID),
szAuthStr, (SWORD)strlen(szAuthStr)); // I got error here
if ( (retcode != SQL_SUCCESS) && (retcode != SQL_SUCCESS_WITH_INFO) ) {
// Connect failed, call SQLGetDiagRec for errors.
}
else {
// Connects to SQL Server always return
// informational messages. These messages can be
// retrieved by calling SQLGetDiagRec.
}
\\---------------------------------------------------------------------
When I compiled it with VC6, I got the error message 'SQLConnectW' : cannot convert parameter 2 from 'char *' to 'unsigned short *'.
Could somebody show me where I do need modified?
Thanh you very much.
I'm trying connect TGE 1.4 demo application to ODBC by my own class like this:
\\------------------------------
#include "stdio.h"
#include "string.h"
#include "windows.h"
#include "sql.h"
#include "sqlext.h"
#include "sqltypes.h"
#include "odbcss.h"
SQLHENV henv = SQL_NULL_HENV;
SQLHDBC hdbc1 = SQL_NULL_HDBC;
SQLHSTMT hstmt1 = SQL_NULL_HSTMT;
IMPLEMENT_CONOBJECT(SQLObject);
void SQLObject::initDBServer()
{
RETCODE retcode;
char *szDSN = "MyDSN", *szUID = "sa", *szAuthStr = "sa";
// Allocate the ODBC Environment and save handle.
retcode = SQLAllocHandle (SQL_HANDLE_ENV, NULL, &henv);
// Notify ODBC that this is an ODBC 3.0 application.
retcode = SQLSetEnvAttr(henv, SQL_ATTR_ODBC_VERSION,
(SQLPOINTER)SQL_OV_ODBC3, SQL_IS_INTEGER);
// Allocate an ODBC connection handle and connect.
retcode = SQLAllocHandle(SQL_HANDLE_DBC, henv, &hdbc1);
retcode = SQLConnect(hdbc1, szDSN, (SWORD)strlen(szDSN),
szUID, (SWORD)strlen(szUID),
szAuthStr, (SWORD)strlen(szAuthStr)); // I got error here
if ( (retcode != SQL_SUCCESS) && (retcode != SQL_SUCCESS_WITH_INFO) ) {
// Connect failed, call SQLGetDiagRec for errors.
}
else {
// Connects to SQL Server always return
// informational messages. These messages can be
// retrieved by calling SQLGetDiagRec.
}
\\---------------------------------------------------------------------
When I compiled it with VC6, I got the error message 'SQLConnectW' : cannot convert parameter 2 from 'char *' to 'unsigned short *'.
Could somebody show me where I do need modified?
Thanh you very much.
About the author
Associate Fyodor -bank- Osokin
Dedicated Logic
May be this can be solution for you.
good luck.