SQL ODBC call from a C BSFN...

vr_cal

Member
Friends, I am attempting to write a C BSFN with direct SQL calls. We are a Windows Shop with SQL2008 database.

So far, I have looked at all posts and the tips they provided and I could get as far as having a successful build (no LNK2019 errors)..For some reason, the SQLConnect seems to be still eluding me.

The BSFN returns back the values for the Env handle, Connect Handle. Lastly, the BSFN is supposed to return a "Y" in the cProceed parm and that is what is not happening. That indicates to me that it is failing when trying to do a SQLConnect.
jdeStrncpyTerminate(szEnvironment, JDB_GetEnvironment(NULL), DIM(szEnvironment));
jdeGetEnvironmentPathCode(hUser, szEnvironment, szPathCode);

JDB_GetObjectDataSource(hUser, _J("F4101"), NULL,
0, szDataSource);

jdeStrcpy((JCHAR *)ServerName,(const JCHAR *)szDataSource);

/* Chop off the trailing blanks */
iCounter=sizeof(ServerName);

while(ServerName[iCounter--]<=' ')
{
ServerName[iCounter+1]='\0';
}

*jdeStrcpy(UserName,JDB_GetUser(NULL));
*jdeStrcpy(Authentication,JDB_GetPassword(NULL));



iRetCode = SQLAllocEnv((SQLHENV)&lpDS->idhEnv);

if (MYSQLSUCCESS(iRetCode))
{
iRetCode = SQLAllocConnect((SQLHENV)lpDS->idhEnv,
(SQLHDBC)&lpDS->idhDbc);

if (MYSQLSUCCESS(iRetCode))
{
iRetCode = SQLConnect((SQLHDBC)lpDS->idhDbc,
(SQLWCHAR *) ServerName,
(SQLSMALLINT)DIM(ServerName),
(SQLWCHAR *) UserName,
(SQLSMALLINT)DIM(UserName),
(SQLWCHAR *) Authentication,
(SQLSMALLINT)DIM(Authentication));

if (MYSQLSUCCESS(iRetCode))
{
lpDS->cProceed = _J('Y');
}
}
}

Any help you can provide would be greatly appreciated.....
 
I once tried to do the same thing and could never really get it to work. I kept having memory violations, heap corruptions, etc. Not that it can't be done, I just seemed to keep having issues. Probably just missing some small little thing.

Anyway, I ended up just writing a separate DLL and then called the DLL functions from the BSFN. The ODBC call code in the DLL was basically the same code I had in the BSFN, for what ever reason it worked fine in the separate DLL but not inside the BSFN. Only downside to this is that you have to distribute your "3rd party" DLL to all the batch servers and any full clients that will execute the ODBC calls.
 
Back
Top