Solved

CDataset and CRecordset DB2 errors

Posted on 2014-03-12
4
329 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
ID: 39924694
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
ID: 39925219
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
ID: 39926378
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
ID: 39927722
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
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.

867 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

16 Experts available now in Live!

Get 1:1 Help Now