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. Connection to remote SQL Server using Qt
Forum Updated to NodeBB v4.3 + New Features

Connection to remote SQL Server using Qt

Scheduled Pinned Locked Moved Solved General and Desktop
qsqldatabasetcpsql serversetdatabasename
4 Posts 3 Posters 3.0k 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.
  • T Offline
    T Offline
    Touchoco
    wrote on last edited by
    #1

    Hello,

    I am trying to connect to a remote SQL Server but I have got the following error message :

    [Microsoft] [SQL Server Native Client 11.0] TCP Provider: A connection attempt failed because the connected party did not respond properly beyond a certain time or a connection did not respond.

    [Microsoft] [SQL Server Native Client 11.0] A network related or instance specific error occurred while establishing a connection to SQL Server. The server cannot be found or is not accessible. Check if the instance name is correct and if SQL Server is configured to allow remote connections. For more information, see SQL Server Books Online. [Microsoft] [SQL Server Native Client 11.0] Connection timeout expired QODBC3: Unable to connect

    I checked :

    • Firewall input/output rules
    • SQL Server is allowing distant connection
    • I can run a remote SQL query with SQL Server Management Studio 18 (server name = 192.168.0.15, port = 1433, user = user_uid, password = password)

    My current code is :

    QString connectString = "Driver={SQL Server Native Client 11.0};";
    connectString.append("Server=169.168.0.15,1433;"); // IP,Port
    connectString.append("Database=remote_database;");  // Schema
    connectString.append("Uid=user_uid;");           // User
    connectString.append("Pwd=password;");           // Pass
    myDataBase.setDatabaseName(connectString);
    

    Before that my code worked with a local SQL Server :

    myDataBase.setDatabaseName(QString("DRIVER={SQL Server Native Client 11.0};SERVER=lpc:MYCOMPUTER\\SQLEXPRESS;Database=local_database;Trusted_Connection=Yes;"));
    myDataBase.setUserName("user_uid");
    myDataBase.setPassword("password");
    

    I tested different options, but I always get the same message

    // With or without SQLEXPRESS
    myDataBase.setDatabaseName(QString("DRIVER={SQL Server Native Client 11.0};SERVER=169.168.0.15\\SQLEXPRESS,1433;Database=remote_database;Trusted_Connection=Yes;"));
    myDataBase.setDatabaseName(QString("DRIVER={SQL Server Native Client 11.0};SERVER=169.168.0.15,1433;Database=remote_database;Trusted_Connection=Yes;"));
    // With (below) or without (above) tcp:
    myDataBase.setDatabaseName(QString("DRIVER={SQL Server Native Client 11.0};SERVER=tcp:169.168.0.15\\SQLEXPRESS,1433;Database=remote_database;Trusted_Connection=Yes;"));
    myDataBase.setDatabaseName(QString("DRIVER={SQL Server Native Client 11.0};SERVER=tcp:169.168.0.15,1433;Database=remote_database;Trusted_Connection=Yes;"));
    //With (above) or without (below) port
    myDataBase.setDatabaseName(QString("DRIVER={SQL Server Native Client 11.0};SERVER=tcp:169.168.0.15\\SQLEXPRESS;Database=remote_database;Trusted_Connection=Yes;"));
    myDataBase.setDatabaseName(QString("DRIVER={SQL Server Native Client 11.0};SERVER=tcp:169.168.0.15;Database=remote_database;Trusted_Connection=Yes;"));
    myDataBase.setDatabaseName(QString("DRIVER={SQL Server Native Client 11.0};SERVER=169.168.0.15\\SQLEXPRESS;Database=remote_database;Trusted_Connection=Yes;"));
    myDataBase.setDatabaseName(QString("DRIVER={SQL Server Native Client 11.0};SERVER=169.168.0.15;Database=remote_database;Trusted_Connection=Yes;"));
    

    I am using :

    • QT 5.15.1
    • Qt Creator 4.12.4
    • mingw32

    Any ideas ?

    artwawA 1 Reply Last reply
    0
    • T Touchoco

      Hello,

      I am trying to connect to a remote SQL Server but I have got the following error message :

      [Microsoft] [SQL Server Native Client 11.0] TCP Provider: A connection attempt failed because the connected party did not respond properly beyond a certain time or a connection did not respond.

      [Microsoft] [SQL Server Native Client 11.0] A network related or instance specific error occurred while establishing a connection to SQL Server. The server cannot be found or is not accessible. Check if the instance name is correct and if SQL Server is configured to allow remote connections. For more information, see SQL Server Books Online. [Microsoft] [SQL Server Native Client 11.0] Connection timeout expired QODBC3: Unable to connect

      I checked :

      • Firewall input/output rules
      • SQL Server is allowing distant connection
      • I can run a remote SQL query with SQL Server Management Studio 18 (server name = 192.168.0.15, port = 1433, user = user_uid, password = password)

      My current code is :

      QString connectString = "Driver={SQL Server Native Client 11.0};";
      connectString.append("Server=169.168.0.15,1433;"); // IP,Port
      connectString.append("Database=remote_database;");  // Schema
      connectString.append("Uid=user_uid;");           // User
      connectString.append("Pwd=password;");           // Pass
      myDataBase.setDatabaseName(connectString);
      

      Before that my code worked with a local SQL Server :

      myDataBase.setDatabaseName(QString("DRIVER={SQL Server Native Client 11.0};SERVER=lpc:MYCOMPUTER\\SQLEXPRESS;Database=local_database;Trusted_Connection=Yes;"));
      myDataBase.setUserName("user_uid");
      myDataBase.setPassword("password");
      

      I tested different options, but I always get the same message

      // With or without SQLEXPRESS
      myDataBase.setDatabaseName(QString("DRIVER={SQL Server Native Client 11.0};SERVER=169.168.0.15\\SQLEXPRESS,1433;Database=remote_database;Trusted_Connection=Yes;"));
      myDataBase.setDatabaseName(QString("DRIVER={SQL Server Native Client 11.0};SERVER=169.168.0.15,1433;Database=remote_database;Trusted_Connection=Yes;"));
      // With (below) or without (above) tcp:
      myDataBase.setDatabaseName(QString("DRIVER={SQL Server Native Client 11.0};SERVER=tcp:169.168.0.15\\SQLEXPRESS,1433;Database=remote_database;Trusted_Connection=Yes;"));
      myDataBase.setDatabaseName(QString("DRIVER={SQL Server Native Client 11.0};SERVER=tcp:169.168.0.15,1433;Database=remote_database;Trusted_Connection=Yes;"));
      //With (above) or without (below) port
      myDataBase.setDatabaseName(QString("DRIVER={SQL Server Native Client 11.0};SERVER=tcp:169.168.0.15\\SQLEXPRESS;Database=remote_database;Trusted_Connection=Yes;"));
      myDataBase.setDatabaseName(QString("DRIVER={SQL Server Native Client 11.0};SERVER=tcp:169.168.0.15;Database=remote_database;Trusted_Connection=Yes;"));
      myDataBase.setDatabaseName(QString("DRIVER={SQL Server Native Client 11.0};SERVER=169.168.0.15\\SQLEXPRESS;Database=remote_database;Trusted_Connection=Yes;"));
      myDataBase.setDatabaseName(QString("DRIVER={SQL Server Native Client 11.0};SERVER=169.168.0.15;Database=remote_database;Trusted_Connection=Yes;"));
      

      I am using :

      • QT 5.15.1
      • Qt Creator 4.12.4
      • mingw32

      Any ideas ?

      artwawA Offline
      artwawA Offline
      artwaw
      wrote on last edited by
      #3

      @Touchoco said in Connection to remote SQL Server using Qt:

      I can run a remote SQL query with SQL Server Management Studio 18 (server name = 192.168.0.15, port = 1433, user = user_uid, password = password)

      but everywhere else you have SERVER=169.168.0.15?

      For more information please re-read.

      Kind Regards,
      Artur

      T 1 Reply Last reply
      1
      • Christian EhrlicherC Offline
        Christian EhrlicherC Offline
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on last edited by
        #2

        Don't see anything Qt-related here what could go wrong - Qt does not change the connection strings but simply pass them to the driver. The ODBC connection strings are a mess. Maybe use another sql browser where you can enter the sql conection strings directly to fiddle out what's the correct one.

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

        1 Reply Last reply
        0
        • T Touchoco

          Hello,

          I am trying to connect to a remote SQL Server but I have got the following error message :

          [Microsoft] [SQL Server Native Client 11.0] TCP Provider: A connection attempt failed because the connected party did not respond properly beyond a certain time or a connection did not respond.

          [Microsoft] [SQL Server Native Client 11.0] A network related or instance specific error occurred while establishing a connection to SQL Server. The server cannot be found or is not accessible. Check if the instance name is correct and if SQL Server is configured to allow remote connections. For more information, see SQL Server Books Online. [Microsoft] [SQL Server Native Client 11.0] Connection timeout expired QODBC3: Unable to connect

          I checked :

          • Firewall input/output rules
          • SQL Server is allowing distant connection
          • I can run a remote SQL query with SQL Server Management Studio 18 (server name = 192.168.0.15, port = 1433, user = user_uid, password = password)

          My current code is :

          QString connectString = "Driver={SQL Server Native Client 11.0};";
          connectString.append("Server=169.168.0.15,1433;"); // IP,Port
          connectString.append("Database=remote_database;");  // Schema
          connectString.append("Uid=user_uid;");           // User
          connectString.append("Pwd=password;");           // Pass
          myDataBase.setDatabaseName(connectString);
          

          Before that my code worked with a local SQL Server :

          myDataBase.setDatabaseName(QString("DRIVER={SQL Server Native Client 11.0};SERVER=lpc:MYCOMPUTER\\SQLEXPRESS;Database=local_database;Trusted_Connection=Yes;"));
          myDataBase.setUserName("user_uid");
          myDataBase.setPassword("password");
          

          I tested different options, but I always get the same message

          // With or without SQLEXPRESS
          myDataBase.setDatabaseName(QString("DRIVER={SQL Server Native Client 11.0};SERVER=169.168.0.15\\SQLEXPRESS,1433;Database=remote_database;Trusted_Connection=Yes;"));
          myDataBase.setDatabaseName(QString("DRIVER={SQL Server Native Client 11.0};SERVER=169.168.0.15,1433;Database=remote_database;Trusted_Connection=Yes;"));
          // With (below) or without (above) tcp:
          myDataBase.setDatabaseName(QString("DRIVER={SQL Server Native Client 11.0};SERVER=tcp:169.168.0.15\\SQLEXPRESS,1433;Database=remote_database;Trusted_Connection=Yes;"));
          myDataBase.setDatabaseName(QString("DRIVER={SQL Server Native Client 11.0};SERVER=tcp:169.168.0.15,1433;Database=remote_database;Trusted_Connection=Yes;"));
          //With (above) or without (below) port
          myDataBase.setDatabaseName(QString("DRIVER={SQL Server Native Client 11.0};SERVER=tcp:169.168.0.15\\SQLEXPRESS;Database=remote_database;Trusted_Connection=Yes;"));
          myDataBase.setDatabaseName(QString("DRIVER={SQL Server Native Client 11.0};SERVER=tcp:169.168.0.15;Database=remote_database;Trusted_Connection=Yes;"));
          myDataBase.setDatabaseName(QString("DRIVER={SQL Server Native Client 11.0};SERVER=169.168.0.15\\SQLEXPRESS;Database=remote_database;Trusted_Connection=Yes;"));
          myDataBase.setDatabaseName(QString("DRIVER={SQL Server Native Client 11.0};SERVER=169.168.0.15;Database=remote_database;Trusted_Connection=Yes;"));
          

          I am using :

          • QT 5.15.1
          • Qt Creator 4.12.4
          • mingw32

          Any ideas ?

          artwawA Offline
          artwawA Offline
          artwaw
          wrote on last edited by
          #3

          @Touchoco said in Connection to remote SQL Server using Qt:

          I can run a remote SQL query with SQL Server Management Studio 18 (server name = 192.168.0.15, port = 1433, user = user_uid, password = password)

          but everywhere else you have SERVER=169.168.0.15?

          For more information please re-read.

          Kind Regards,
          Artur

          T 1 Reply Last reply
          1
          • artwawA artwaw

            @Touchoco said in Connection to remote SQL Server using Qt:

            I can run a remote SQL query with SQL Server Management Studio 18 (server name = 192.168.0.15, port = 1433, user = user_uid, password = password)

            but everywhere else you have SERVER=169.168.0.15?

            T Offline
            T Offline
            Touchoco
            wrote on last edited by
            #4

            @artwaw

            Thanks a lot ! It works.

            I don't know how I could miss this one. It seems that every time I restart the server, the IP changes. I will have to set a fixed IP adress.

            1 Reply Last reply
            0

            • Login

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