Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. QtonPi
  4. How do I get PyQt5-QSql set up on Raspberry Pi

How do I get PyQt5-QSql set up on Raspberry Pi

Scheduled Pinned Locked Moved Unsolved QtonPi
1 Posts 1 Posters 277 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    evanmars
    wrote on 8 Aug 2024, 18:14 last edited by evanmars 8 Aug 2024, 18:29
    #1

    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.

    1 Reply Last reply
    0

    1/1

    8 Aug 2024, 18:14

    • Login

    • Login or register to search.
    1 out of 1
    • First post
      1/1
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved