Solved

CDataset and CRecordset DB2 errors

Posted on 2014-03-12
4
335 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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
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 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.

617 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