Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2009-03

SQLDB invalid handle

6 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Stephano

The following code produces an error:

   ODBCConnection1.Connected := True;
   SQLQuery1.Active := True;
   SQLQuery1.Active := false;
   ODBCConnection1.Connected := False;
   ODBCConnection1.Connected := True;
   SQLQuery1.Active := True;              <- error
   SQLQuery1.Active := false;
   ODBCConnection1.Connected := False;

error is: could not prepare statement
Last return code: SQL_INVALID_HANDLE
Invalid handle passed to SQLGetDiagRec/Field

Has anybody encountered this before?

Reply by email

Bram Kuijvenhoven
to Stephano

Dear Stephano,

Stephano wrote
The following code produces an error:

Could you please provide some more details?
- FPC version
- A minimal but complete test program demonstrating the error

To ensure reproducibility of the problem, please report under which configuration of OS, DBMS and ODBC driver your minimal test program showed the problem.

It would also be great if you had a stack trace (see http://wiki.freepascal.org/Creating_a_Backtrace_with_GDB).

error is: could not prepare statement Last return code: SQL_INVALID_HANDLE Invalid handle passed to SQLGetDiagRec/Field

So far I can see that the call to SQLPrepare failed (in TODBCConnection.PrepareStatement), but that unfortunately the ODBC error message could not be retrieved.

Regards,

Bram Kuijvenhoven

Reply by email

Stephano
to Bram Kuijvenhoven
Bram Kuijvenhoven wrote 6 lines
Could you please provide some more details? - FPC version - A minimal but complete test program demonstrating the error It would also be great if you had a stack trace (see http://wiki.freepascal.org/Creating_a_Backtrace_with_GDB).

FPC 2.2.2
Lazarus v0.9.27 r18956 i386-win32-win32/win64
Win XP
Sybase 6
Test project attached

So far I can see that the call to SQLPrepare failed (in TODBCConnection.PrepareStatement), but that unfortunately the ODBC error message could not be retrieved.

Very possible as even a prepare instead of the 2nd open would give the same error

Backtrace:
#0 0x0040ad46 in fpc_raiseexception ()
#1 0x0054cfce in
ODBCCONN_ODBCCHECKRESULT$crc8B09F779_CHECKSQLGETDIAGRESULT$SMALLINT () #2 0x0007f1d0 in ?? ()
#3 0x0054cd42 in
ODBCCONN_ODBCCHECKRESULT$SMALLINT$SMALLINT$POINTER$ANSISTRING$ array_of_const ()
#4 0x0054d06f in
ODBCCONN_ODBCCHECKRESULT$SMALLINT$SMALLINT$POINTER$ANSISTRING ()
#5 0x0054dd38 in
ODBCCONN_TODBCCONNECTION_$__PREPARESTATEMENT$TSQLCURSOR$TSQLTR ANSACTION$ANSISTRING$TPARAMS ()
#6 0x00549911 in SQLDB_TCUSTOMSQLQUERY_$__PREPARE () #7 0x0054a23d in SQLDB_TCUSTOMSQLQUERY_$__INTERNALOPEN () #8 0x00551340 in DB_TDATASET_$__DOINTERNALOPEN () #9 0x000f6de8 in ?? ()
#10 0x00551e9a in DB_TDATASET_$__OPENCURSOR$BOOLEAN () #11 0x000f6d01 in ?? ()
#12 0x00552196 in DB_TDATASET_$__SETACTIVE$BOOLEAN () #13 0x00549683 in SQLDB_TCUSTOMSQLQUERY_$__SETACTIVE$BOOLEAN () #14 0x000f6de8 in ?? ()
#15 0x00623958 in $STDCTRLS$_Ld71 ()
#16 0x0041ebb6 in TFORM1__BUTTON1CLICK (SENDER=0x1b09518, this=0x1b090c8) at unit1.pas:42
#17 0x0048dcc4 in TCONTROL__CLICK (this=0x1b09518) at control.inc:2108 #18 0x0049e75f in TBUTTONCONTROL__CLICK (this=0x1b09518) at buttoncontrol.inc:63
#19 0x0049ec25 in TCUSTOMBUTTON__CLICK (this=0x1b09518) at buttons.inc:164 #20 0x0049f151 in TBUTTON__CLICK (this=0x1b09518) at buttons.inc:320 #21 0x0049e62a in TBUTTONCONTROL__WMDEFAULTCLICKED (MESSAGE= {MSG = 66567, WPARAM = 5209264, LPARAM = -591746099, RESULT = 0, WPARAMLO
= 31920, WPARAMHI = 79, LPARAMLO = 43981, LPARAMHI = 56506, RESULTLO = 0, RESULT
HI = 0}, this=0x1b09518) at buttoncontrol.inc:26
#22 0x0040a699 in SYSTEM_TOBJECT_$__DISPATCH$formal () #23 0x0049e610 in TBUTTONCONTROL__ISCHECKEDSTORED (this=0x7f758) at buttoncontrol.inc:22
#24 0x00484bc4 in TWINCONTROL__WNDPROC (MESSAGE=
{MSG = 66567, WPARAM = 5209264, LPARAM = -591746099, RESULT = 0, WPARAMLO
= 31920, WPARAMHI = 79, LPARAMLO = 43981, LPARAMHI = 56506, RESULTLO = 0, RESULT
HI = 0}, this=0x1b09518) at wincontrol.inc:4804
#25 0x00514ba7 in DELIVERMESSAGE (TARGET=0x1b09518, AMESSAGE=void) at lclmessageglue.pas:111
#26 0x004f9f8d in WINDOWPROC (WINDOW=1902210, MSG=273, WPARAM=38168, LPARAM=656932) at win32callback.inc:2443
#27 0x77d48709 in USER32!GetDC () from C:\WINDOWS\system32\user32.dll #28 0x001d0682 in ?? ()
#29 0x00000111 in ?? ()
#30 0x00009518 in ?? ()
#31 0x000a0624 in ?? ()
#32 0x004f7cb0 in GETNEEDPARENTPAINT (AWINDOWINFO=0x4f7cb0, AWINCONTROL=0x7f7d4) at win32callback.inc:205
#33 0x77d487eb in USER32!GetDC () from C:\WINDOWS\system32\user32.dll #34 0x004f7cb0 in GETNEEDPARENTPAINT (AWINDOWINFO=0x0, AWINCONTROL=0x77d48808)
at win32callback.inc:205
#35 0x77d4b743 in USER32!GetParent () from C:\WINDOWS\system32\user32.dll #36 0x00000000 in ?? () from
#37 0x004f7cb0 in GETNEEDPARENTPAINT (AWINDOWINFO=0x7f830, AWINCONTROL=0x1d0682) at win32callback.inc:205
#38 0x77d4b7ab in USER32!SendMessageW () from C:\WINDOWS\system32\user32.dll #39 0x007d8890 in ?? ()
#40 0x017d7bd0 in ?? ()
#41 0x00009518 in ?? ()
#42 0x000a0624 in ?? ()
#43 0x00000000 in ?? () from
#44 0x00150808 in ?? ()
#45 0x0007f87c in ?? ()
#46 0x773f6ff6 in ImageList_Duplicate ()
from
C:\WINDOWS\WinSxS\x86_Microsoft.Windows.Common-Controls_6595b64144ccf1df _6.0.2600.2180_x-ww_a84f1ff9\comctl32.dll
#47 0x001d0682 in ?? ()
#48 0x00000111 in ?? ()
#49 0x00009518 in ?? ()
#50 0x000a0624 in ?? ()
#51 0x00000001 in ?? ()
#52 0x00150808 in ?? ()
#53 0x0007f898 in ?? ()
#54 0x773f70d8 in ImageList_Duplicate ()
from
C:\WINDOWS\WinSxS\x86_Microsoft.Windows.Common-Controls_6595b64144ccf1df _6.0.2600.2180_x-ww_a84f1ff9\comctl32.dll
#55 0x00150808 in ?? ()
#56 0x00000000 in ?? () from
#57 0x000a0028 in ?? ()
#58 0x00150808 in ?? ()
#59 0x00000001 in ?? ()
#60 0x0007f928 in ?? ()
#61 0x773f93dd in ImageList_Duplicate ()
from
C:\WINDOWS\WinSxS\x86_Microsoft.Windows.Common-Controls_6595b64144ccf1df _6.0.2600.2180_x-ww_a84f1ff9\comctl32.dll
#62 0x00150808 in ?? ()
#63 0x00000001 in ?? ()
#64 0x0007f990 in ?? ()
#65 0x773f8b56 in ImageList_Duplicate ()
from
C:\WINDOWS\WinSxS\x86_Microsoft.Windows.Common-Controls_6595b64144ccf1df _6.0.2600.2180_x-ww_a84f1ff9\comctl32.dll
#62 0x00150808 in ?? ()
#63 0x00000001 in ?? ()
#64 0x0007f990 in ?? ()
#65 0x773f8b56 in ImageList_Duplicate ()
from
C:\WINDOWS\WinSxS\x86_Microsoft.Windows.Common-Controls_6595b64144ccf1df _6.0.2600.2180_x-ww_a84f1ff9\comctl32.dll
---Type <return> to continue, or q <return> to quit--- #66 0x00000000 in ?? () from
#67 0x0007f88c in ?? ()
#68 0x0007f8ec in ?? ()
#69 0x00000001 in ?? ()
#70 0x00000012 in ?? ()
#71 0x0007f8d4 in ?? ()
#72 0x00000000 in ?? () from
#73 0x00000000 in ?? () from
#74 0x00000012 in ?? ()
#75 0x000a0028 in ?? ()
#76 0x000a0624 in ?? ()
#77 0x00000000 in ?? () from
#78 0x00000000 in ?? () from
#79 0x0007f87c in ?? ()
#80 0x004fbb7a in SENDPAINTMESSAGE (CONTROLDC=1378312, parentfp=0x0) at win32callback.inc:371
Previous frame inner to this frame (corrupt stack?) -------------- next part --------------
A non-text attachment was scrubbed...
Name: ODBCopen.zip
Type: application/x-zip-compressed
Size: 3000 bytes
Desc: not available
Url : http://www.lazarus.freepascal.org/pipermail/lazarus/attachments/20090314/d3b5755f/attachment-0001.bin

Reply by email

Bram Kuijvenhoven
to Stephano
Stephano wrote 13 lines
Bram Kuijvenhoven wrote: > Could you please provide some more details? > - FPC version > - A minimal but complete test program demonstrating the error > > It would also be great if you had a stack trace (see > http://wiki.freepascal.org/Creating_a_Backtrace_with_GDB). > FPC 2.2.2 Lazarus v0.9.27 r18956 i386-win32-win32/win64 Win XP Sybase 6 Test project attached

Thank you. I don't have a Sybase server or even a Sybase ODBC driver here, but after modifying your code to connect to a MySQL server that I have running, I also got an exception (an Access Violation actually).

However, when I use the SQLDB and ODBConn units from FPCs trunk (rev. 12825), the program no longer crashes. Since some changes were made between 2.2.2 and trunk in the code that allocates and deallocates statement handles, the crash may have been fixed.

Could you please test with FPCs trunk? (shortcut: copy the .inc/.pp/.pas files to your test program's directory from trunk/packages/fcl-db/src/, subdirs base, dbase, sqldb and sqldb/odbc)

BTW your test program depends on the LCL, but this is not necessary; you may find it easier to test with a command line program.

Regards,

Bram

Reply by email

Stephano
to Bram Kuijvenhoven
Bram Kuijvenhoven wrote 8 lines
Thank you. I don't have a Sybase server or even a Sybase ODBC driver here, but after modifying your code to connect to a MySQL server that I have running, I also got an exception (an Access Violation actually). However, when I use the SQLDB and ODBConn units from FPCs trunk (rev. 12825), the program no longer crashes. Since some changes were made between 2.2.2 and trunk in the code that allocates and deallocates statement handles, the crash may have been fixed. Could you please test with FPCs trunk? (shortcut: copy the .inc/.pp/.pas files to your test program's directory from trunk/packages/fcl-db/src/, subdirs base, dbase, sqldb and sqldb/odbc) BTW your test program depends on the LCL, but this is not necessary; you may find it easier to test with a command line program.

I tested with FPC trunk and the problem persists!

Reply by email

Stephano
to Bram Kuijvenhoven: Thank you. I don't have a Sybase server or even a Sybase ODBC driver here, but after…
Bram Kuijvenhoven wrote
I don't have a Sybase server or even a Sybase ODBC driver here, but after modifying your code to connect to a MySQL server that I have running, I also got an exception (an Access Violation actually).

Note that if the query SQL is invalid (such as a non existing table name in SELECT), I get an Access Violation instead. Did you adapt the SQL to your database?

On the other hand, I tested FPC 2.2.2 with Firebird (ODBC) and it gives the same error. However, with IBConnection instead of ODBCConnection, there is no error. So the error lies specifically in TODBCConnection.

Reply by email