Results 1 to 3 of 3

Thread: SQL connection problem

  1. #1
    Join Date
    Feb 2007
    Posts
    39
    Thanks
    13
    Qt products
    Qt4
    Platforms
    Windows

    Default SQL connection problem

    I've the following problem while trying to access a sql database through ip address
    My code:



    Qt Code:
    1. QSqlDatabase db = QSqlDatabase::addDatabase("QPSQL");
    2. db.setHostName("66.xx.xxx.xxx");//ip masked for privacy
    3. db.setDatabaseName("john_stuff");
    4. db.setUserName("john_stuff");
    5. db.setPassword("12345");
    6.  
    7.  
    8. bool ok = db.open();
    9. error = db.lastError();
    10. if( ok )
    11. {
    12. ...
    13. }
    To copy to clipboard, switch view to plain text mode 

    I tried using different sql driver, QSQLITE, QPSQL and QPSQL7

    Results using:
    QSQLITE: ok = true, no errors throwed but no matter what ip address, username, password i enter it always say it's ok?
    No firewall warnings.

    QPSQL and QPSQL7: ok = false, lasterror always says
    driver error: QPSQL: Unable to connect
    databaseError: {"could not connect to server: Can't assign requested address (0x00002741/10049) Is the server running on host "66.xx.xxx.xxx" and accepting
    TCP/IP connections on port 5432? " size=162}
    ErrorType: ConnectionError
    errorNumber: -1
    My firewall throws a warning so it's really trying to connect to something online

    I didn't understood the port warning so i tried using db.setPort( 3306 ) because in the past i used a program that used this port number to access the same database and it worked ok.
    Results were: ok = false
    databaseError {"expected authentication request from server, but received A" size=60}


    I know that my available drivers are: QSQLITE QODBC3 QODBC QPSQL7 QPSQL

    I'm total newbie at sql stuff, what i'm doing wrong here?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: SQL connection problem

    What database you want to connect to? Judging from the port, it's MySQL, so most likely you have to use QMYSQL driver.

  3. #3
    Join Date
    Oct 2006
    Posts
    42
    Thanks
    1
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: SQL connection problem

    QSQLITE always works because it doesn't connect to a remote database, but creates a local one on your computer. See http://www.sqlite.org/ for more info on SQLite.

    As Jacek says you need to know what kind of database you're trying to connect to. Is it PostgreSql or MySql or something else? And you need to set the correct port as well, unless the database uses its default port.

    If it's a MySql database as the port number suggests (3306) you need to build the QMYSQL driver and use this.
    Last edited by mm78; 24th May 2007 at 19:20.

Similar Threads

  1. Problem building Firebird sql plugins
    By vieraci in forum Installation and Deployment
    Replies: 11
    Last Post: 12th September 2008, 01:28
  2. Signal-slots connection problem.
    By impeteperry in forum Qt Tools
    Replies: 26
    Last Post: 23rd January 2007, 14:33
  3. SQL problem
    By nimmyj in forum Qt Programming
    Replies: 4
    Last Post: 25th December 2006, 18:43
  4. Connection with MS SQL
    By manish_pesit in forum Qt Programming
    Replies: 4
    Last Post: 13th September 2006, 07:47
  5. connection problem
    By mhoover in forum Qt Programming
    Replies: 1
    Last Post: 7th July 2006, 22:14

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.