How do I get PyQt5-QSql set up on Raspberry Pi
Unsolved
QtonPi
-
I have been using PyODBC successfully to connect to and query a MSSQL database.
I now want an app that uses PyQt5 for GUI and I noticed that there is a SQL module in PyQt5, so I thought "Why not use that so I have fewer dependencies and imports?"
I could just go on using PyODBC, but I would like to use PyQt5 for learning purposes, if nothing else.I set up PyODBC as follows:
def get_cnx_cursor(): connect = pyodbc.connect( "Driver={FreeTDS};" "Server=MYSERVER;" "Port=1433;" "Database=mydatabase;" "UID=myusername;" "PWD=mypassword;" "TDS_Version=7.3;" return connect, connect.cursor()
That works.
Trying to set up connection with PyQt5:
def createConnection(): connString = f'DRIVER={{SQL Driver}};"\ f'SERVER=MYSERVER;"\ f'PORT=1433;"\ f'DATABASE=mydatabase;"\ f'UID=myusername;"\ f'PWD=mypassword;" global db db = QSqlDatabase.addDatabase('QODBC3') db.setDatabaseName(connString) if db.open(): print('Connected') else: print('Connection Failed') createConnection()
Returns "Connection Failed"
I don't know what I'm doing (obviously) and can't find the info I need.