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. connect to sql server

connect to sql server

Scheduled Pinned Locked Moved General and Desktop
12 Posts 4 Posters 7.3k Views
  • 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.
  • H Offline
    H Offline
    hamedaz
    wrote on 21 Dec 2015, 06:23 last edited by
    #1

    Hi
    I was attached sql server in Qt
    As long as I connected database in sql server
    The program works correctly, but when your database
    I cut not connected(deattach) in sql server
    Not connected to the database,Error Messages:QSqlQuery::exec: database not open
    My database directory is located in the folder debug program
    code:
    QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
    db.setConnectOptions();
    QString dbPath = QCoreApplication::applicationDirPath() +"/managetablo.mdf";
    db.setDatabaseName("Driver={SQL Server Native Client 10.0};Server=.;AttachDbFilename"+dbPath+";Database=db;Trusted_Connection=Yes");
    db.open();
    this->model = new QSqlQueryModel();
    model->setQuery("SELECT * FROM [managetablo].[dbo].[Vistor]");
    ui->tableView->setModel(model);

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mrdebug
      wrote on 21 Dec 2015, 09:47 last edited by
      #2

      Hi. You should use query.lastError().text() (better is to implement try - catch) to have the error details.
      Maybe with Sql Server you can use QAxObject("ADODB.Connection").

      Regards.

      Need programmers to hire?
      www.labcsp.com
      www.denisgottardello.it
      GMT+1
      Skype: mrdebug

      H 1 Reply Last reply 21 Dec 2015, 12:54
      0
      • M mrdebug
        21 Dec 2015, 09:47

        Hi. You should use query.lastError().text() (better is to implement try - catch) to have the error details.
        Maybe with Sql Server you can use QAxObject("ADODB.Connection").

        Regards.

        H Offline
        H Offline
        hamedaz
        wrote on 21 Dec 2015, 12:54 last edited by
        #3

        @mrdebug
        I changed my code as follows:
        ////////
        if(db.open()){
        qDebug() <<"open";

           QSqlQuery qry;
           if(qry.exec("SELECT * FROM [managetablo].[dbo].[Vistor]"))
           {
              while(qry.next())
              {
                   qDebug() <<qry.value(0).toString();
              }
           }
           else
           {
               qDebug()<< "error:"<<db.lastError().text();
        
           }
           qDebug() <<"close";
           db.close();
        

        }
        else
        {
        qDebug()<< "error:"<<db.lastError().text();
        }

        }
        /////////
        When I attach the database in sql server studio
        Information is read and true But when
        database is detach,Information from databse Not Read
        Following messages from qDebug statement:
        open
        error: " "
        close

        1 Reply Last reply
        0
        • H Offline
          H Offline
          hskoglund
          wrote on 21 Dec 2015, 13:44 last edited by
          #4

          Hi maybe your SQL Server Browser service is not running, try starting it, usually it's located in something like C:\Program Files (x86)\Microsoft SQL Server\90\Shared\

          sqlbrowser.exe -c
          
          H 1 Reply Last reply 21 Dec 2015, 14:33
          0
          • H hskoglund
            21 Dec 2015, 13:44

            Hi maybe your SQL Server Browser service is not running, try starting it, usually it's located in something like C:\Program Files (x86)\Microsoft SQL Server\90\Shared\

            sqlbrowser.exe -c
            
            H Offline
            H Offline
            hamedaz
            wrote on 21 Dec 2015, 14:33 last edited by
            #5

            @hskoglund said:

            Hi maybe your SQL Server Browser service is not running, try starting it, usually it's located in something like C:\Program Files (x86)\Microsoft SQL Server\90\Shared\

            sqlbrowser.exe -c
            

            I told you to run commands,but I received the following error message:
            sql browser:failed starting OLAP redirection services with error 1

            1 Reply Last reply
            0
            • H Offline
              H Offline
              hskoglund
              wrote on 21 Dec 2015, 15:14 last edited by
              #6

              Hmmm I'm guessing but try to turn off your firewall and/or antivirus program.

              1 Reply Last reply
              0
              • H Offline
                H Offline
                Hamed.Masafi
                wrote on 21 Dec 2015, 15:18 last edited by Hamed.Masafi
                #7
                • Remove Database=db; from connecting string
                • Convert Trusted_Connection=Yes to Integrated Security=SSPI; (or Integrated Security=True;)
                • Test again.

                Remote object sharing (OO RPC)
                http://forum.qt.io/topic/60680/remote-object-sharing-oo-rpc-solved

                Advanced, Powerful and easy to use ORM for Qt5
                https://forum.qt.io/topic/67417/advanced-powerful-and-easy-to-use-orm-for-qt5

                H 1 Reply Last reply 21 Dec 2015, 20:07
                0
                • H Hamed.Masafi
                  21 Dec 2015, 15:18
                  • Remove Database=db; from connecting string
                  • Convert Trusted_Connection=Yes to Integrated Security=SSPI; (or Integrated Security=True;)
                  • Test again.
                  H Offline
                  H Offline
                  hamedaz
                  wrote on 21 Dec 2015, 20:07 last edited by
                  #8

                  @Hamed.Masafi said:

                  • Remove Database=db; from connecting string
                  • Convert Trusted_Connection=Yes to Integrated Security=SSPI; (or Integrated Security=True;)
                  • Test again.

                  Like talking to you
                  I connecting string made
                  The message error gives the following:

                  error: "[Microsoft][SQL Server Native Client 10.0][SQL Server]Login failed for user ''. [Microsoft][SQL Server Native Client 10.0]Invalid connection string attribute QODBC3: Unable to connect"

                  1 Reply Last reply
                  0
                  • M Offline
                    M Offline
                    mrdebug
                    wrote on 22 Dec 2015, 15:38 last edited by
                    #9

                    Please try to use this Qt Sql utility
                    http://www.denisgottardello.it/ADOTest/ADOTestWin32.zip
                    by clicking on "Open from datasource", following the wizard and at the end trying to write and run a query in the sql field.
                    If this utility works on your machine than can I can help you.

                    Need programmers to hire?
                    www.labcsp.com
                    www.denisgottardello.it
                    GMT+1
                    Skype: mrdebug

                    H 1 Reply Last reply 22 Dec 2015, 17:20
                    0
                    • M mrdebug
                      22 Dec 2015, 15:38

                      Please try to use this Qt Sql utility
                      http://www.denisgottardello.it/ADOTest/ADOTestWin32.zip
                      by clicking on "Open from datasource", following the wizard and at the end trying to write and run a query in the sql field.
                      If this utility works on your machine than can I can help you.

                      H Offline
                      H Offline
                      hamedaz
                      wrote on 22 Dec 2015, 17:20 last edited by
                      #10

                      @mrdebug
                      I could
                      Connect to database
                      And could query run

                      1 Reply Last reply
                      0
                      • M Offline
                        M Offline
                        mrdebug
                        wrote on 22 Dec 2015, 23:09 last edited by
                        #11

                        You should use the QAxObject object
                        QAXOConn= new QAxObject("ADODB.Connection");
                        and Ado to manage databases.
                        I normally use QSqlDatabase object to manage sqlite and PostgreSql databases but with the others (SqlServer, Oracle, DBII) I normally use Ado.
                        After you have implemented Ado you can manage each type of databases because all databases have the Ado drivers (PostgreSql maybe not)

                        Need programmers to hire?
                        www.labcsp.com
                        www.denisgottardello.it
                        GMT+1
                        Skype: mrdebug

                        H 1 Reply Last reply 23 Dec 2015, 05:31
                        0
                        • M mrdebug
                          22 Dec 2015, 23:09

                          You should use the QAxObject object
                          QAXOConn= new QAxObject("ADODB.Connection");
                          and Ado to manage databases.
                          I normally use QSqlDatabase object to manage sqlite and PostgreSql databases but with the others (SqlServer, Oracle, DBII) I normally use Ado.
                          After you have implemented Ado you can manage each type of databases because all databases have the Ado drivers (PostgreSql maybe not)

                          H Offline
                          H Offline
                          hamedaz
                          wrote on 23 Dec 2015, 05:31 last edited by
                          #12

                          @mrdebug said:

                          QAXOConn= new QAxObject("ADODB.Connection");

                          Thanks for your answer
                          I was searching the ado in qt
                          I could not find how to use the Internet
                          You can give a sample code

                          1 Reply Last reply
                          0

                          1/12

                          21 Dec 2015, 06:23

                          • Login

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