Solved

Sybase does not allow more than one active statement when retrieving results without a cursor

Posted on 2006-07-20
6
1,439 Views
Last Modified: 2008-01-09
Does anyone know what this error message means and how to resolve it ?
0
Comment
Question by:colechr
6 Comments
 
LVL 10

Expert Comment

by:bret
Comment Utility
What program is raising the error?  What version of what Sybase database product are you using?
0
 
LVL 19

Accepted Solution

by:
grant300 earned 500 total points
Comment Utility
I believe you are trying to write a client application program that issues an SQL statement while you are still returning results from the prior statement.  This can be something you are doing on purpose or by accident.  Let's look at the accidental case first.

Before you can issue a command, the command/connection handle has to be in the correct state.  If you have issued a command that returns multiple rows and/or multiple result sets, you must either exhaust the return of all rows in all result sets, or clear the command (essentially tell it to abandon any remaining results and prepare to be used again.)  It may not be obvious that even for a simple select statement, you will likely get two result sets.  The first has the rows you want in it.  The second is a MSG result set that has the @@ROWCOUNT value in it.

The correct way to code a client application is to have an inner and outer loop.  The outer loop handles each result set (regardless of type) until there are none left and the inner handles the rows from each result set.  BTW, I can think of at least four different kinds of result sets including a regular, message, error, and compute.  There is some example code published with the client libraries that should help.

If you are trying to return partial results and do some kind of processing on them as they come in that requires database activity, you have a couple of choices.  CT_LIB support Asynchronous connections that will allow you to have more than one active command at a time.  This is kind of a pain in the neck because you have to handle callbacks and stuff.  Possible but not pretty.  The other method is to open up a second connection to the database.  This is a common technique for writing client/server applications against Sybase.  It works well because a Sybase connection is so fast to make and is such low overhead that you don't need to worry about loading up the server.  Typically, one connection is used to do all the reads while the other is reserved for writes (insert/update/delete).

Hope this helps,
Bill
0
 
LVL 6

Expert Comment

by:ChrisKing
Comment Utility
Basically, it means you have not finished fetching all the rows
(either in the current result set, or in following result sets)
before you have executed the next command
0
 
LVL 3

Expert Comment

by:dave_gr
Comment Utility
You're trying to do 2 queries over one connection.  Finish (and close) the first before starting the next one.  If you need both queries open at the same time use two distinct connections to the database.
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

Learn to move / copy / export exchange contacts to iPhone without using any software. Also see the issues in configuration of exchange with iPhone to migrate contacts.
Find out what Office 365 Transport Rules are, how they work and their limitations managing Office 365 signatures.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

744 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