Results 1 to 5 of 5

Thread: QSqldatabase open() failed to connect SQL server on other than default 1433 port

  1. #1
    Join Date
    Dec 2011
    Posts
    3
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Question QSqldatabase open() failed to connect SQL server on other than default 1433 port

    SQL server uses other than default 1433 port (e.g. 5555), system DSN created using the port 5555 and tested completed successfully.

    However, QSqlDatabase failed to open database.

    The code snippets:

    Qt Code:
    1. QSqlDatabase *db = QSqlDatabase :: addDatabase("QODBC");
    2. db->setDatabaseName("test");
    3. db->setUserName(userName);
    4. db->setPassword(passWord);
    5.  
    6. if ( db->open() ){
    7. ///Database open successfully.....
    8. }
    9. else
    10. {
    11. ///Database open failed
    12. }
    To copy to clipboard, switch view to plain text mode 

    It's greatly appreciated for any help to solve this problem.
    Last edited by helen; 5th December 2011 at 21:24.

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QSqldatabase open() failed to connect SQL server on other than default 1433 port

    What is
    Qt Code:
    1. QSqlDatabase::lastError().text()
    To copy to clipboard, switch view to plain text mode 
    telling you?

  3. #3
    Join Date
    Dec 2011
    Posts
    3
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: QSqldatabase open() failed to connect SQL server on other than default 1433 port

    Thank you for your reply. The lastError().test() prints out as follow.

    "[Microsoft][ODBC SQL Server Driver][DBNETLIB]SQL Server does not exist or access denied. [Microsoft][ODBC SQL Server Driver][DBNETLIB]ConnectionOpen (Connect()). QODBC3: Unable to connect"

    Is any possible it still uses default 1433 port instead of specified port 5555?

  4. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QSqldatabase open() failed to connect SQL server on other than default 1433 port

    Check that with QSqlDatabase::port(). Because in your example code you do not set the port.

  5. #5
    Join Date
    Dec 2011
    Posts
    3
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: QSqldatabase open() failed to connect SQL server on other than default 1433 port

    QSqlDatabase.port() return -1.
    Last edited by helen; 5th December 2011 at 21:22.

Similar Threads

  1. Connect to server with ip port and password (telnet)
    By halvors in forum Qt Programming
    Replies: 5
    Last Post: 6th April 2010, 19:23
  2. QSqlDatabase - How to connect to multiple database?
    By cutie.monkey in forum Qt Programming
    Replies: 4
    Last Post: 10th March 2010, 13:03
  3. Why QSqlDatabase::open() returns open?
    By gboelter in forum Newbie
    Replies: 7
    Last Post: 27th August 2009, 19:52
  4. QSqlDatabase default MySQL unix socket path
    By daggilli in forum Qt Programming
    Replies: 0
    Last Post: 21st September 2008, 20:55
  5. cannot connect to QSqldatabase
    By mave-rick in forum Qt Programming
    Replies: 3
    Last Post: 19th August 2008, 18:52

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.