Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. How to connect pyqt5 desktop application to an sql server management studio database on a different computer.
Forum Updated to NodeBB v4.3 + New Features

How to connect pyqt5 desktop application to an sql server management studio database on a different computer.

Scheduled Pinned Locked Moved Unsolved Qt for Python
2 Posts 2 Posters 834 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.
  • L Offline
    L Offline
    LT-K101
    wrote on 8 Aug 2023, 12:00 last edited by LT-K101 8 Aug 2023, 12:06
    #1

    Am trying to connect a python script on computer A to Microsoft server management studio database on computer B. I did the following and am getting the error message below. Please I need help this is my first time implementing this and am struggling with this.

    import pyodbc
    
    # Connection parameters
    server = '192.178.45.10'
    database = 'test'
    username = 'DESKTOP-SE75VSF\User-PC'
    password = 'pass'
    
    # Create a connection string
    connection_string = f'DRIVER=SQL Server;SERVER={server};DATABASE={database};UID={username};PWD={password}'
    
    try:
        # Establish connection
        connection = pyodbc.connect(connection_string)
        cursor = connection.cursor()
    
    
       # Close cursor and connection
        cursor.close()
        connection.close()
    
    except pyodbc.Error as e:
        print('Error:', e)
    
    

    Error saying I get error pyodbc. InterfaceError: ('IM002', '[IM002] [MICROSOFT] [ODBC Driver Manager] Data source name not found and no default driver specified (0) (SQL DriverConnect)')

    J 1 Reply Last reply 8 Aug 2023, 12:07
    0
    • L LT-K101
      8 Aug 2023, 12:00

      Am trying to connect a python script on computer A to Microsoft server management studio database on computer B. I did the following and am getting the error message below. Please I need help this is my first time implementing this and am struggling with this.

      import pyodbc
      
      # Connection parameters
      server = '192.178.45.10'
      database = 'test'
      username = 'DESKTOP-SE75VSF\User-PC'
      password = 'pass'
      
      # Create a connection string
      connection_string = f'DRIVER=SQL Server;SERVER={server};DATABASE={database};UID={username};PWD={password}'
      
      try:
          # Establish connection
          connection = pyodbc.connect(connection_string)
          cursor = connection.cursor()
      
      
         # Close cursor and connection
          cursor.close()
          connection.close()
      
      except pyodbc.Error as e:
          print('Error:', e)
      
      

      Error saying I get error pyodbc. InterfaceError: ('IM002', '[IM002] [MICROSOFT] [ODBC Driver Manager] Data source name not found and no default driver specified (0) (SQL DriverConnect)')

      J Online
      J Online
      JonB
      wrote on 8 Aug 2023, 12:07 last edited by JonB 8 Aug 2023, 12:18
      #2

      @LT-K101 said in How to connect pyqt5 desktop application to an sql server management studio database on a different computer.:

      connection_string = f'DRIVER=SQL Server;SERVER={server};DATABASE={database};UID={username};PWD={password}'

      I trust this is not actually the literal string you pass, is it? [OIC, you have defined the Python variables for interpolation, got it.]

      Your code is 100% Python with its internal database connection library. You do not use Qt or Qt's SQL database library here, so your question would best be addressed to a Python forum rather than a Qt one.

      P.S.

      DRIVER=SQL Server

      Are you sure this correct? Where did you copy this from? You sure it wasn't supposed to be

      DRIVER={SQL Server}
      

      Even then I'm not sure whether SQL Server isn't a very old name to use for the driver?

      Otherwise various suggestions in, say, https://stackoverflow.com/questions/46045834/pyodbc-data-source-name-not-found-and-no-default-driver-specified or other hits by Googling the error message.

      Finally, just to make sure: the MS SQL Server you want to connect to on the server is running a default instance of MSSQL Server, right? Not a named instance?

      1 Reply Last reply
      2

      1/2

      8 Aug 2023, 12:00

      • Login

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