Visual Studio Qt 5.11.2 SQL Server Express 2017 Driver
-
wrote on 13 Nov 2018, 12:22 last edited by aha_1980
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!
-
wrote on 14 Nov 2018, 07:54 last edited by sneubert
-
The Driver parameter in the connection string has to exactly match the driver name in ODBC admin drivers page.
Maybe you have some typo. And even this is windows, the name is case sensitive!
wrote on 14 Nov 2018, 14:58 last edited by@sneubert Thank you! I undestand now what happened there.
-
@sneubert Thank you! I undestand now what happened there.
wrote on 15 Nov 2018, 05:46 last edited by@Ovidiu_GCO
{SQL Server Native Client 17.0 };
What is with the blank in front of "}"
1/4