Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. I cant connect Qt to SqlSERVER
Forum Updated to NodeBB v4.3 + New Features

I cant connect Qt to SqlSERVER

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 305 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.
  • A Offline
    A Offline
    Aboniabo
    wrote on 22 Apr 2024, 19:01 last edited by
    #1

    Hi, im a noob trying to connect to a database from a SQL server 2012, the thing is no matter what i try i cant seem to make it work on qt, I receive this error every time "[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified, IM002 QODBC: Unable to connect"
    And I don't get why because when i try to connect with python using pyodbc with the exact same setup it connects without any issues,
    Can someone please point me in the right direction i already looked to a lot of responses and solutions to no avail, I already tried reinstalling the drivers on my windows machine, i've tried other drivers, I already tried putting my dns source in user and system
    This i my c++ code :

    QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
    
        db.setDatabaseName("DRIVER={SQL Server};SERVER=server;DATABASE=ejemplo;UID=user;PWD=password");
    
        if(db.open())
        {
            qDebug() << "Opened";
            db.close();
        }
        else
            qDebug() << "Error" << db.lastError().text();
    
        db.close();
    

    And this is my python code

    import pyodbc
    try:
        
        connection = pyodbc.connect('DRIVER={SQL Server};SERVER=server;DATABASE=ejemplo;UID=user;PWD=password)
        cursor = connection.cursor()
    
        # SQL query to list table names
        cursor.execute("SELECT name FROM sys.tables")
    
        # Print the table names
        for row in cursor:
            print(row[0])
    
    except pyodbc.Error as err:
        print("Connection error:", err)
    
    finally:
        if connection:
            connection.close()
    
    C 1 Reply Last reply 22 Apr 2024, 19:03
    0
    • A Aboniabo
      22 Apr 2024, 19:01

      Hi, im a noob trying to connect to a database from a SQL server 2012, the thing is no matter what i try i cant seem to make it work on qt, I receive this error every time "[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified, IM002 QODBC: Unable to connect"
      And I don't get why because when i try to connect with python using pyodbc with the exact same setup it connects without any issues,
      Can someone please point me in the right direction i already looked to a lot of responses and solutions to no avail, I already tried reinstalling the drivers on my windows machine, i've tried other drivers, I already tried putting my dns source in user and system
      This i my c++ code :

      QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
      
          db.setDatabaseName("DRIVER={SQL Server};SERVER=server;DATABASE=ejemplo;UID=user;PWD=password");
      
          if(db.open())
          {
              qDebug() << "Opened";
              db.close();
          }
          else
              qDebug() << "Error" << db.lastError().text();
      
          db.close();
      

      And this is my python code

      import pyodbc
      try:
          
          connection = pyodbc.connect('DRIVER={SQL Server};SERVER=server;DATABASE=ejemplo;UID=user;PWD=password)
          cursor = connection.cursor()
      
          # SQL query to list table names
          cursor.execute("SELECT name FROM sys.tables")
      
          # Print the table names
          for row in cursor:
              print(row[0])
      
      except pyodbc.Error as err:
          print("Connection error:", err)
      
      finally:
          if connection:
              connection.close()
      
      C Online
      C Online
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on 22 Apr 2024, 19:03 last edited by
      #2

      @Aboniabo If you're using Qt 6.7.0 then wait for 6.7.1 or downgrade to 6.6.2 as you can see in the forum search: https://forum.qt.io/topic/156080

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      A 1 Reply Last reply 22 Apr 2024, 19:51
      1
      • C Christian Ehrlicher
        22 Apr 2024, 19:03

        @Aboniabo If you're using Qt 6.7.0 then wait for 6.7.1 or downgrade to 6.6.2 as you can see in the forum search: https://forum.qt.io/topic/156080

        A Offline
        A Offline
        Aboniabo
        wrote on 22 Apr 2024, 19:51 last edited by
        #3

        @Christian-Ehrlicher Omg i was going crazy thank you so much

        1 Reply Last reply
        0
        • A Aboniabo has marked this topic as solved on 22 Apr 2024, 19:51

        1/3

        22 Apr 2024, 19:01

        • Login

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