I cant connect Qt to SqlSERVER
-
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()
-
@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
-
@Christian-Ehrlicher Omg i was going crazy thank you so much
-