Solved

CDataset and CRecordset DB2 errors

Posted on 2014-03-12
4
324 Views
Last Modified: 2014-03-19
Hi all,

My connection string is
"Driver={IBM DB2 ODBC DRIVER};Database=db;Hostname=host;Port=50000;Protocol=TCPIP;Uid=uid;Pwd=pwd"

I am trying to execute sql statements like these:
string sql="{CALL DBO.SP_ALERT(99,'1974-03-26-11.00.11.000','4754',334,445,1,85,16,22,0,0,0,0,0,17,9)}";
or
string sql="UPDATE FM.WARNING SET ACTIVE = 0 WHERE ID=99 and TYPEID = 2 and ACTIVE=1;";

CDatabase pDatabase=new CDatabase();
pDatabase->Open(_T(""),FALSE,FALSE,LPCTSTR(sCnString));
pDatabase->ExecuteSQL(sql.c_str());

I am receiving "CLI0115E  Invalid cursor state. SQLSTATE=24000" and "Function sequence error" all the time.

What am I doing wrong?
0
Comment
Question by:trustworthy
  • 2
4 Comments
 
LVL 86

Expert Comment

by:jkr
Comment Utility
What does 'Open()' return? You are not specifying a data source in your connection string, so you should pass that in the 1st parameter, which is empty in your case. See http://msdn.microsoft.com/en-us/library/7ca7bkdw.aspx ("CDatabase::Open")
0
 
LVL 24

Expert Comment

by:chaau
Comment Utility
For ODBC calls date and time literals need to be escaped:
date literals:  {d 'yyyy-mm-dd'}
timestamp literals: {ts 'yyyy-mm-dd hh:mm:ss'}.
Try to convert you statement to this, and see how it goes:
string sql="{CALL DBO.SP_ALERT(99, {ts '1974-03-26 11:00:11.000'}, '4754', 334, 445, 1, 85, 16, 22, 0, 0, 0, 0, 0, 17, 9)}";

Open in new window

0
 

Author Comment

by:trustworthy
Comment Utility
Actually, I moved a little further with this problem.

I got all select statements working, but I always get "Function sequence error"
on the update statements, like this one:
"UPDATE FM.WARNING SET ACTIVE = 0 WHERE ID=1228 and TYPEID = 2 and ACTIVE=1"

I tried to update the driver - IBM Data Server Driver Package (IBMDBCL1) - but that didn't help.

What else could be the reason for that error?
Am I installing the wrong driver?

Please help.
0
 
LVL 24

Accepted Solution

by:
chaau earned 500 total points
Comment Utility
It is a weird DB2-specific error (bug). It requires you to set a certain ODBC/CLI parameter.
The parameter in question is PATCH1. Please scroll down the page at the hyperlink above and find a PATCH1 parameter value of 1024. Setting of this parameter makes:
Returns SQL_SUCCESS_WITH_INFO instead of SQL_NO_DATA_FOUND from the SQLExecute() and SQLExecDirect() functions if the executed UPDATE or DELETE statement affected no rows. This value might be needed by some Microsoft Visual Basic applications.
BTW, there are a ton other parameters you can set to make your driver work better. I recommend you to review them all.
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now