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. Visual Studio Qt 5.11.2 SQL Server Express 2017 Driver
Forum Updated to NodeBB v4.3 + New Features

Visual Studio Qt 5.11.2 SQL Server Express 2017 Driver

Scheduled Pinned Locked Moved Solved General and Desktop
sql serverodbcbeginnerc++ qt
4 Posts 3 Posters 1.8k Views 1 Watching
  • 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.
  • O Offline
    O Offline
    Ovidiu_GCO
    wrote on 13 Nov 2018, 12:22 last edited by aha_1980
    #1

    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 replacing

    Driver = {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!

    1 Reply Last reply
    0
    • S Offline
      S Offline
      sneubert
      wrote on 14 Nov 2018, 07:54 last edited by sneubert
      #2

      The Driver parameter in the connection string has to exactly match the driver name in ODBC admin drivers page.

      0_1542182004593_odbc.PNG

      Maybe you have some typo. And even this is windows, the name is case sensitive!

      O 1 Reply Last reply 14 Nov 2018, 14:58
      5
      • S sneubert
        14 Nov 2018, 07:54

        The Driver parameter in the connection string has to exactly match the driver name in ODBC admin drivers page.

        0_1542182004593_odbc.PNG

        Maybe you have some typo. And even this is windows, the name is case sensitive!

        O Offline
        O Offline
        Ovidiu_GCO
        wrote on 14 Nov 2018, 14:58 last edited by
        #3

        @sneubert Thank you! I undestand now what happened there.

        A 1 Reply Last reply 15 Nov 2018, 05:46
        0
        • O Ovidiu_GCO
          14 Nov 2018, 14:58

          @sneubert Thank you! I undestand now what happened there.

          A Offline
          A Offline
          Andy314
          wrote on 15 Nov 2018, 05:46 last edited by
          #4

          @Ovidiu_GCO
          {SQL Server Native Client 17.0 };
          What is with the blank in front of "}"

          1 Reply Last reply
          0

          4/4

          15 Nov 2018, 05:46

          • Login

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