By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,004 Members | 1,253 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,004 IT Pros & Developers. It's quick & easy.

DB2SetCLPEnv_api not working with DB2 version 9

P: 1
Hello,
I am trying to port an exising product to support DB v9.
This is a piece of code similar to the one in the product

if(DB2SetCLPEnv_api (GetCurrentProcessId()) == 0)
{
char buff[2048];
FILE *fp = NULL;

runCmd = L"\"C:\\Program Files\\IBM\\SQLLIB\\BIN\\DB2\" connect to MYDB user db2admin using \'db2admin\'";

if ( (fp = _popen(runCmd.c_str(), "rt")) != NULL)
{
while (fgetts(buff, 2048, fp) != NULL )
{
printf(L"%s",buff);
}
}
else
{
printf("Unable to execute command \n");
}
runCmd = L"\"C:\\Program Files\\IBM\\SQLLIB\\BIN\\DB2\" select grantee, granteetype, grantor from syscat.dbauth where bindaddauth = \'Y\'";

if((fp = _wpopen(runCmd.c_str(), L"rt")) != NULL)
{
while (fgetts(buff, 2048, fp) != NULL )
{
printf(L"%s",buff);
}
}
else
{
printf(L"Unable to execute command \n");
}
}
else
{
printf("Unable to set DB2 CLP \n");
}

Basically what i am try to do is to call DB2SetCLPEnv_api and execute two commands using _popen. The _popen function creates a pipe and asynchronously executes a spawned copy of the command processor with the specified string command. The first command connects to MYDB using the username and password provided. The second command executes a select query.

In v8 the connection establised using the command
DB2 connect to MYDB user db2admin using 'db2admin'
seems to persist until a
DB2 connect reset
is called and the select query executes correctly.

in v9 the connection establised using the command
DB2 connect to MYDB user db2admin using 'db2admin'
gets terminated immediately and when i try to execute the second command i get an error that says

SQL1024N A database connection does not exist. SQLSTATE=08003

The above mentioned code is being built on different platforms including most flavours of windows and Linux. A major code change would require significant development and testing effort. Can anyone provide me with a solution to fix this.

Thnaks and Regards
myDB2Queries
Feb 5 '07 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.