Subject Re: SQL error code 502
Author nitaligavino <Dan.Crea@apropos.com>
Hi John:

Here is some info that I have based on my experience working with
cursors via the API directly. I have done my development in C / C++
so I hit the API at a low level. Never the less the concept should
be the same.

The error you are getting might be one of two things. First you may
already have a cursor with the same name within the database. Or
there may be an error in the cursor name format. I'm guessing that
the cursor name is already in use however. Maybe by a different
client connection. Cursor names must be totally unique. That is the
uniqueness must span process boundaries. Since the database is
process independent N clients can connect and the database engine
must keep the cursor names separate. So if you have say two clients
applications that connect to the database and both are creating
cursors with the same name you can get the 502 error. Client
application 1 creates cursor "cursor1" and then Client application 2
tries to create the same cursor "cursor1" you will get the error.
Although the cursor name is tied to a statement handle it still seems
to require total uniqueness. Also, I have seen that cursors fail if
the name is not formatted correctly. For some reason, I don't have a
good explanation why, cursor names must start with an alpha
character. That is a cursor name of "1234" will fail but "cur_1234"
is valid.

I ran into similar problems early in my development and found that
that a good way of formatting a cursor name was to use the current
time and process instance.

C example:

strcpy(chCursor, "cur");
sprintf(chCursor + strlen(chCursor), "%08x_%02u%02u%02u%02u%02u",
lSeed,
t->tm_sec, t->tm_min, t->tm_hour, t->tm_mday,
t->tm_mon);

The cursor name that this produces looks something like this:
Cur12345678_33100512

Please note that I only give this info from my experience and don't
clam to have any inside expertise.

Dan


--- In ib-support@yahoogroups.com, "jacaley <john.acaley@v...>"
<john.acaley@v...> wrote:
> Can anyone tell me what may be causing the following error:
>
> Dynamic SQL Error
> SQL error code = -502
> Declared Cursor already exists
>
> I'm using Delphi 5.01 w/Firebird. The error doesn't happen
everytime
> and I've never gotten it to happen while debugging.
>
> Thanks,
> John