mkleehammer / pyodbc

Python ODBC bridge
https://github.com/mkleehammer/pyodbc/wiki
MIT No Attribution
2.88k stars 561 forks source link

python code crashes while connecting hfsql with pyodbc #1273

Closed snegithar closed 9 months ago

snegithar commented 9 months ago

Please first make sure you have looked at:

Environment

To diagnose, we usually need to know the following, including version numbers. On Windows, be sure to specify 32-bit Python or 64-bit:

Issue python crashes while connecting with HFSQL

Often it is easiest to describe your issue as "expected behavior" and "observed behavior".

Trying to connect hfsql using pyodbc, but after executing this pyodbc.connect(connstr) python crashes and rest of the code are not executing even try/execute is there

sample code:

import pyodbc try: pyodbc.connect('Driver={HFSQL};Server Name = 127.0.0.1;Server Port =4900;Database = test;UID = Admin;IntegrityCheck=1') except Exception as ex: print(ex)

Error : No error has thrown

v-chojas commented 9 months ago

Could you post an ODBC trace?

snegithar commented 9 months ago

No trace from ODBC...i have attached the image for your reference.

image

v-chojas commented 9 months ago

That doesn't look like a crash but an exit.

Did you try to create an ODBC trace?

gordthompson commented 9 months ago

Try running this VBScript and see if it works. (Save it as a .vbs file and then double-click it.)

' hfsql_test.vbs
connection_str = "Driver={HFSQL};Server Name = 127.0.0.1;Server Port =4900;Database = test;UID = Admin;IntegrityCheck=1"
Set cnxn = CreateObject("ADODB.Connection")
cnxn.Open connection_str
WScript.Echo "connected"
snegithar commented 9 months ago

That doesn't look like a crash but an exit.

Did you try to create an ODBC trace?

@v-chojas As i am new to pyodbc, could you please help me with the creation of ODBC trace?

snegithar commented 9 months ago

Try running this VBScript and see if it works. (Save it as a .vbs file and then double-click it.)

' hfsql_test.vbs
connection_str = "Driver={HFSQL};Server Name = 127.0.0.1;Server Port =4900;Database = test;UID = Admin;IntegrityCheck=1"
Set cnxn = CreateObject("ADODB.Connection")
cnxn.Open connection_str
WScript.Echo "connected"

@gordthompson Thank you. I tried and it's working. But i want it to be connected via pyodbc.

gordthompson commented 9 months ago

That doesn't look like a crash but an exit. Did you try to create an ODBC trace?

@v-chojas As i am new to pyodbc, could you please help me with the creation of ODBC trace?

https://github.com/mkleehammer/pyodbc/wiki/Troubleshooting-%E2%80%93-Generating-an-ODBC-trace-log

snegithar commented 9 months ago

@gordthompson @v-chojas

i have attached the odbc trace log for your reference.

SQL.LOG

gordthompson commented 9 months ago

You could try using pypyodbc instead of pyodbc to see if it works better.

snegithar commented 9 months ago

@gordthompson Sure, will try. But i just want to know why it is not working via pyodbc?

v-chojas commented 9 months ago

This appears to be a driver bug since the last thing that happened was a call to SQLGetData which never returns. You can check the Application log in the Event Viewer to see if it was a silent crash.

gordthompson commented 9 months ago

The driver does seem to have an issue with SQLGetData getting called after SQLGetTypeInfo. This is the tail of the log file:

400  python  Sample  13b4-2870  ENTER SQLGetTypeInfo 
401         HSTMT               0x0139CC48
402         SWORD                       12 <SQL_VARCHAR>
403  
404  python  Sample  13b4-2870  EXIT  SQLGetTypeInfo  with return code 0 (SQL_SUCCESS)
405         HSTMT               0x0139CC48
406         SWORD                       12 <SQL_VARCHAR>
407  
408  python  Sample  13b4-2870  ENTER SQLFetch 
409         HSTMT               0x0139CC48
410  
411  python  Sample  13b4-2870  EXIT  SQLFetch  with return code 0 (SQL_SUCCESS)
412         HSTMT               0x0139CC48
413  
414  python  Sample  13b4-2870  ENTER SQLGetData 
415         HSTMT               0x0139CC48
416         UWORD                        3 
417         SWORD                        4 <SQL_C_LONG>
418         PTR                 <unknown type>
419         SQLLEN                     4
420         SQLLEN *            0x00000000

Earlier in the file there is the exact same sequence of calls. That SQLGetData call doesn't EXIT either. The program just proceeds with calling SQLSetEnvAttr, but it does not crash.

260  python  Sample  3228-2fb0  ENTER SQLGetTypeInfo 
261         HSTMT               0x00CCCC48
262         SWORD                       12 <SQL_VARCHAR>
263  
264  python  Sample  3228-2fb0  EXIT  SQLGetTypeInfo  with return code 0 (SQL_SUCCESS)
265         HSTMT               0x00CCCC48
266         SWORD                       12 <SQL_VARCHAR>
267  
268  python  Sample  3228-2fb0  ENTER SQLFetch 
269         HSTMT               0x00CCCC48
270  
271  python  Sample  3228-2fb0  EXIT  SQLFetch  with return code 0 (SQL_SUCCESS)
272         HSTMT               0x00CCCC48
273  
274  python  Sample  3228-2fb0  ENTER SQLGetData 
275         HSTMT               0x00CCCC48
276         UWORD                        3 
277         SWORD                        4 <SQL_C_LONG>
278         PTR                 <unknown type>
279         SQLLEN                     4
280         SQLLEN *            0x00000000
281  
282  python  Sample  13b4-2870  ENTER SQLSetEnvAttr 
283         SQLHENV             0x00000000
284         SQLINTEGER                 201 <SQL_ATTR_CONNECTION_POOLING>
285         SQLPOINTER                 2 <SQL_CP_ONE_PER_HENV>
286         SQLINTEGER                   4