SQLError Invalid Cursor

forum.sourcecode (2000-2005) & forum.td.sourcecode (2005-2010)
ldx

SQLError Invalid Cursor

Post by ldx » 11 Mar 2008, 10:10

 Posted by:  ldx 

Hi,

As far as I can see, there are multiple ways to trap SQL errors,
such as the SAM_SqlError message, or the "When SQLError" handler.
But the one error that I can't seem to trap is "Invalid cursor"

Centura seems to just always pop up a messagebox that states the error.
Is there a way to trap an invalid cursor error in code?

Thanks!

Regards,
ldx

FRBhote
India
Posts: 2201
Joined: 09 Mar 2017, 05:32
Location: Hyderabad, India

Re: SQLError Invalid Cursor

Post by FRBhote » 11 Mar 2008, 12:04

 Posted by:  F R Bhote 

This error would occur when the cursor used is not connected - it would
probably have a value of null.

Jim McNamara

Re: SQLError Invalid Cursor

Post by Jim McNamara » 11 Mar 2008, 16:26

 Posted by:  Jim McNamara 

Without trying to be a wise ass - there is an error in your code. It's
trying to use a handle that:

A Has never been connected
B Has been disconnect
C Is out of scope

You can test for hSql = hWndNULL but that will only trap A and C - unless
after you disconnect a handle you religiously Set hSql = hWndNULL

ldx

Re: SQLError Invalid Cursor

Post by ldx » 11 Mar 2008, 16:30

 Posted by:  ldx 

Yes, you ar right,
there is an error in my code. No doubt about that! :-)

The problem is that I need to locate the error.
I'm quite sure that A is not the problem.
It's either B or C.

The section of code where the error occurs is quite large, and there are
quite some Sql Handles in use.
As far as I can see, the "Invalid Cursor" message does not contain any extra
information.
I would like to know which handle is causing the problem.

Since this error occurs in an application which is already in production,
I don't have the luxury of adding many logging lines or iterating through
numerous updates
to pinpoint the error.
I need some way to get extra information on the error without much impact on
the
application's operation.
I was hoping that there was some way to catch the invalid cursor error in
code,
and extract some additional information from it (like the handle and maybe
the cause
or the location in code where the error was generated) or in the very least
give a sensible
error message to our not-so-tech-savvy users.
Much in the same way as I can do with a regular SQL error.

Does anyone of you know of a way to do that?

Regards,
ldx

Jeff Luther
Site Admin
Site Admin
United States of America
Posts: 2370
Joined: 04 Mar 2017, 18:34
Location: Palm Springs, California

Re: SQLError Invalid Cursor

Post by Jeff Luther » 11 Mar 2008, 17:44

 Posted by:  Jeff Luther 

The issue is that TD is catching this error, not the DB, so there's no
'sql error.' (it's a TD runtime error.)

TD is catching this because it's doing a lookup in its struct of sql
handles and finds that hSql is invalid, or as in the case of the jpg
I've attached, SqlDisconnect() sets hSql = 0 and TD catches it as a 0
handle. (A Sql Handle is a complex struct; TD just uses the var. Sql
Handle as a simple number, which is then an offset into this array of
structs of all handles connected. First hSql = 1h, 2nd = 2h, etc.)

"... [at] the very least give a sensible error message [for an invalid
handle]" - Well you can, yes and no. Yes, because it can be done to
catch your hSql handles before a call , but no, because I don't see it
can be done without some changes to your code.

"I was hoping that there was some way to catch the invalid cursor error
in code" - To catch the error yourself, you would have to add some code.
Either:
1 - as Jim says, use: "If hSql = hWndNULL" or "!=" before any/all of
your Sql calls and do error handling in a function, say;

2 - or write a function that all your Sql commands go through and eval.
the handle passed before it gets used in a Sqlxxx() call.

You just can't do that extra error handling without adding some code,
because it's a coding and/or logic error, not a backend/db/sql error.

Alternatively--and likely fewer places--add a little code before/after
each of your SqlDisconnect() calls? Since you think B or C is the
problem, the code could alert when a disconnect was being done too early.

Best Regards,
Jeff @ PC Design
info. & samples: www.JeffLuther.net/unify/

You do not have the required permissions to view the files attached to this post.

ldx

Re: SQLError Invalid Cursor

Post by ldx » 12 Mar 2008, 08:43

 Posted by:  ldx 

Hi Jeff,

Thanks for this elaborate explanation and for fixing the mistakes in my
english :-)

I guess I'll have to add the NULL-check before each Sql* call.
I was affraid it was going to have to be like that.
I guess it was just wishfull thinking that this error could be caught
in a construct similar to "When SqlError"

It would be nice though if TD would allow us to do our own error-handling
when an invalid cursor-error occurs. Oh Well,
I guess I'll start adding those checks now.
Thanks for the help guys.

Regards,
ldx

Jeff Luther
Site Admin
Site Admin
United States of America
Posts: 2370
Joined: 04 Mar 2017, 18:34
Location: Palm Springs, California

Re: SQLError Invalid Cursor

Post by Jeff Luther » 12 Mar 2008, 17:15

 Posted by:  Jeff Luther 

"it would be nice though if TD would allow us to do our own
error-handling when an invalid cursor-error occurs" - well, coding that
is no different than trying to ref. any hWnd var. in an appl. that is
invalid and needing your own error-handling do do that.

Win. programmers code in an ASSERT( hWnd ) or similiar to catch this
themselves. And TD programmers should code in If hWnd = hWndNULL to do
the same thing (or write their own ASSERT() call).

Are you connecting/disconnecting all over your appl? And there's one too
many disconnects? Is that the issue?

That seems the real crux of the problem, not catching an error because
the code(r) has made one. Sql Handles are meant to be reused; there's no
need to conn/disconn in every function, for example. They can be (and
should be) reused. A new handle during the life of a dlg. box makes
sense to me, but within the body of a main appl. they are generally reused.

Best Regards,
Jeff @ PC Design
info. & samples: www.JeffLuther.net/unify/

Return to “td.sourcecode”

Who is online

Users browsing this forum: [Ccbot] and 0 guests