Visual Studio Qt 5.11.2 SQL Server Express 2017 Driver
Solved
General and Desktop
-
Hello!
I am facing a problem with the ODBC connection. I am trying to connect to my SQL Server Express 2017 Instance, but it seems that i am not able to do it. (There are no errors/warnings).This is my code:
#include "f1_system.h" #include <ActiveQt/qaxobject.h> #include <QtSql/qsqldatabase.h> F1_System::F1_System(QWidget *parent) : QMainWindow(parent) { ui.setupUi(this); connect(ui.loginPushButton, SIGNAL(clicked()), this, SLOT(validateLogin())); } QString F1_System::connect2DB() { QString connectionString = QStringLiteral("Driver={SQL Server Native Client 17.0 };Server=DESKTOP-4K9MAS2\\SQLEXPRESS01;Database=Formula1_BD;Trusted_Connection=yes;"); QSqlDatabase db = QSqlDatabase::addDatabase("QODBC"); db.setDatabaseName(connectionString); if (db.open()) return QString("Connected"); else return QString("Not Connected!"); } void F1_System::validateLogin() { ui.label->setText(connect2DB()); }
It keeps changing the text to "Not Connected!".
Could someone let me know what is the problem?[Later edit]
-- SOLVED --
I solved it by replacingDriver = {SQL Server Native Client 17.0 }
with
Driver = {SQL Server}
I don't really understand why it is working now, so now I could use some explanations on it. (or, at least, some hints)
Thank you!
-
@Ovidiu_GCO
{SQL Server Native Client 17.0 };
What is with the blank in front of "}"