0

I'm trying to use PyODBC to connect to a HFSQL database. I'm close to getting it to work, but there's something I can't figure out.

Here's my code :

import pyodbc
import pandas as pd

def main():
    engine = 'Driver={HFSQL};Server Name=10.11.0.17;Server Port=4900;Database=suivi_dossiers;UID=admin;PASSWORD='
    cnx = pyodbc.connect(engine)
    cursor = cnx.cursor()
    cursor.execute("SHOW TABLES")
    for x in cursor.fetchall():
        print(x)

    data = pd.read_sql("SELECT * FROM CLIENTS",cnx)
    print(data)

if __name__=='__main__':
    main()

Note that the database doesn't require any password. And I know the parameters are correct because if I change them just a slight bit, it gives me an error !

Using the debugger and prints, I figured out that this script crashes when the line cnx = pyodbc.connect(dsn) gets reached, but it's not instantly. As if it was able to connect, but somewhere during this, it crashes for any reason.

What's worse is that it doesn't even crashes, it just ends the process right there. Meaning that it doesn't even try other lines of code (of prints after the line). And using Try/Except doesn't do anything more. So I don't know what to do honestly.

It's important to note that I tried this exact code/logic on a MySQL database working the same way, and it works, no crash at any moment.

I also tried setting up a DSN from the ODBC system, and it gives the exact same result as without the DSN.

Also, the ODBC is properly working with HFSQL because when I use the ODBC method on PowerBI, I'm able to fetch the data from the HFSQL database. So the issue surely comes from PYODBC.

I also tried using PyPyODBC which was recommended at some point, but it hasn't been updated for years (last Python version supported was 3.3)

So if anyone knows, even just a workaround that would help me reach this awful database, that would be great ! Thanks !

0 Answers0