Solved

CDataset and CRecordset DB2 errors

Posted on 2014-03-12
4
333 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 25

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 25

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

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…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
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.

752 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