The original BJTIMES project had used the built-in Windows ADO framework for connecting to the DB. This limits the solution to run only on Windows. I am modifying the solution to use ODBC so that with the use of Windows/Linux ODBC drivers, we can run the solution on Windows as well as Linux
I tried to convert the ADO to ODBC but when I run the solution it says failed to connect. That means it is not connected to Database. But it works fines in ADO version though
try
{ //following ODBC functions to establish connection
if (SQL_SUCCESS == SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &SqlEnvHandle ))
if (SQL_SUCCESS == SQLSetEnvAttr(getEnvironment(), SQL_ATTR_ODBC_VERSION, (SQLPOINTER)SQL_OV_ODBC3, 0))
if (SQL_SUCCESS == SQLAllocHandle(SQL_HANDLE_DBC, getEnvironment(), &SqlConnectionHandle ))
{
SQLCHAR retconstring[RETURN_CODE_SZ];
SQLRETURN retcode = SQLDriverConnect( //establishing the connection to DB
getConnection(),
NULL,
connect,
SQL_NTS,
retconstring,
1024,
NULL,
SQL_DRIVER_NOPROMPT);
if ((retcode == SQL_SUCCESS) || (retcode == SQL_SUCCESS_WITH_INFO))
{
isConnected = true;
sprintf(m_ErrStr, "Success");
IsConnected = true;
return IsConnected;
}
else
{
sprintf(m_ErrStr, "Failed to connect");
return false;
}
}
}
CATCHERROR(SqlConnectionHandle,0);
return false;
}
This is the part of code for the connection to the database.
In the above code is there variable that uses ADO rather than ODBC. It looks like SQLdriverconnect has some problem. How can I figure out the problem?