Results 1 to 16 of 16

Thread: connect to sql server

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Posts
    273
    Qt products
    Qt3 Qt4
    Platforms
    Windows
    Thanks
    42
    Thanked 1 Time in 1 Post

    Question Re: connect to sql server

    Hi Dimitri.
    I have installed QT4.1.1 not from binary..from the exe file

    My output of QSqlDatabase::drivers() is: QODBC, QODBC3, QSQLITE

    My last Post was a example for QT3 thats why QODBC3...

    Example SQL Browser show me QSQLITE and QODBC and not QODBC3
    Last edited by raphaelf; 26th February 2006 at 19:24.
    Think DigitalGasoline

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: connect to sql server

    Do you get any messages from Qt? What exactly happens?

  3. #3
    Join Date
    Jan 2006
    Posts
    273
    Qt products
    Qt3 Qt4
    Platforms
    Windows
    Thanks
    42
    Thanked 1 Time in 1 Post

    Default Re: connect to sql server

    hi,
    with following code i ca not read the message complete, but it say something about Error on connecting user "sa". Reason: no security SQL Server connection..
    Qt Code:
    1. QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
    2. db.setHostName("localhost");
    3. db.setDatabaseName("DRIVER={SQL Server};SERVER=localhost;DATABASE=inventar;UID=sa;PWD=raphaelf");
    4. db.setUserName("sa");
    5. db.setPassword("raphaelf");
    6. if(!db.open()){
    7. QMessageBox::information(this,"",db.lastError().text());
    8. return false;
    9. }
    10. return true;
    To copy to clipboard, switch view to plain text mode 

    If i try like following i get this error: Data Source Name not found and no default driver specified QODBC3 : Unable to connect
    Qt Code:
    1. ..
    2. db.setDatabaseName("inventar");
    3. ..
    To copy to clipboard, switch view to plain text mode 
    Last edited by raphaelf; 26th February 2006 at 21:25.
    Think DigitalGasoline

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: connect to sql server

    So the problem lies not in Qt or your application but in the database engine configuration. Try to connect with a different user, MS SQL may have non-secure connections for "sa" (system-admin) user disabled.

  5. #5
    Join Date
    Feb 2006
    Posts
    4
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: connect to sql server

    /************************************************** ******
    **连接sqlserver
    **
    ************************************************** *******/
    bool UpgradeWizardPage::ConnectionSqlServer(QString user,QString password,QString host,QString database)
    {
    QSqlDatabase db = QSqlDatabase::addDatabase("QODBC","QODBC1");//and connectionName

    // db= QSqlDatabase::addDatabase("QODBC","QODBC1");
    db.setDatabaseName("DRIVER={SQL Server};Server="+host+";Database="+database+";Uid= "+user+";Pwd="+password+";");
    db.setHostName(host);

    db.setUserName(user);
    db.setPassword(password);
    db.setConnectOptions("SQL_ATTR_CONNECTION_TIMEOUT= 60");

    if (!db.open()) {
    return false;
    }else{
    return true;
    }
    }


    it's worked well,why you have programe?have you installed the sqlserver's odbc driver???

  6. #6
    Join Date
    Jan 2006
    Posts
    273
    Qt products
    Qt3 Qt4
    Platforms
    Windows
    Thanks
    42
    Thanked 1 Time in 1 Post

    Default Re: connect to sql server

    hi everybody,

    I have tried at my Office to connect from client to our Server and it run Perfekt! We have MS SQL Server 7.0 installed there..hmmm..could by that ODBC doesent support the newer Version?

    Thanks for all replies

    here the code:
    Qt Code:
    1. QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
    2. db.setHostName("pcpsr5");
    3. db.setDatabaseName("DRIVER={SQL Server};SERVER=pcpsr5;DATABASE=inventar;UID=sa;PWD=xxxxx");
    4. db.setUserName("sa");
    5. db.setPassword("xxxxx");
    6. if(!db.open())
    7. {
    8. QMessageBox::information(this, "Application name",
    9. "not connected");
    10. return false;
    11.  
    12. }
    13. else
    14. QMessageBox::information(this, "Application name",
    15. "connected");
    16. return true;
    To copy to clipboard, switch view to plain text mode 
    Think DigitalGasoline

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: connect to sql server

    It could be that in the office the server is configured differently. Try to connect to the server without Qt, using regular sql console provided with the dbms (if there is one) to see if you can connect to the server at all.

  8. #8
    Join Date
    Jan 2006
    Posts
    273
    Qt products
    Qt3 Qt4
    Platforms
    Windows
    Thanks
    42
    Thanked 1 Time in 1 Post

    Default Re: connect to sql server

    Hi Wysota!

    You are right..It was not a QT Problem. It was on my SQL Server at my Machine..
    It was a Authentification Setting. I had to choose: "SQL Server and Windows"

    Thank you very much...

    Thanks for open my mind

    This is the best forum!
    Think DigitalGasoline

Similar Threads

  1. Poor performance with Qt 4.3 and Microsoft SQL Server
    By Korgen in forum Qt Programming
    Replies: 2
    Last Post: 23rd November 2007, 10:28
  2. Connect to a server, send data and exit
    By Pepe in forum Newbie
    Replies: 6
    Last Post: 27th July 2007, 11:29
  3. cannot connect to X server
    By jcr in forum Qt Programming
    Replies: 1
    Last Post: 18th April 2007, 14:22
  4. Replies: 1
    Last Post: 4th October 2006, 16:05
  5. Sql Server cannot retrieve data from select
    By Atomino in forum Qt Programming
    Replies: 10
    Last Post: 7th September 2006, 16:37

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.