Results 1 to 3 of 3

Thread: Problem with connection to MS SQL on Linux

  1. #1
    Join Date
    Dec 2014
    Posts
    1
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android

    Default Problem with connection to MS SQL on Linux

    Hello,
    I have Problem with connection to MS SQL on Linux
    My code looks like this:
    Qt Code:
    1.  
    2. m_db = QSqlDatabase::addDatabase("QODBC3");
    3. m_db.setDatabaseName("DRIVER={ms};SERVER=192.168.7.23;TDS_VERSION=8.0;PORT=1433;DATABASE=Hamownia;UID=admin;PWD=haslo;");
    4.  
    5. qDebug() << "polaczono" << m_db.open();
    6. qDebug() << "DRIVERS :" << QSqlDatabase::drivers();
    7. qDebug() << "error" << m_db.lastError();
    8.  
    9. if(!m_db.open()){
    10. qDebug()<<"ERROR: "<<QSqlError(m_db.lastError()).text();
    11. } else {
    12. qDebug()<<"Ok";
    13. }
    To copy to clipboard, switch view to plain text mode 

    Program replay:
    Qt Code:
    1. root@raspberrypi:/home/pi/kompilacje/qt/sql_console# ./sql_console
    2. polaczono false
    3. DRIVERS : ("QMYSQL3", "QMYSQL", "QODBC3", "QODBC")
    4. error QSqlError(0, "QODBC3: Unable to connect", "[unixODBC][Driver Manager]Data source name not found, and no default driver specified")
    5. ERROR: "[unixODBC][Driver Manager]Data source name not found, and no default driver specified QODBC3: Unable to connect"
    To copy to clipboard, switch view to plain text mode 

    isql connect without any problems:
    Qt Code:
    1. root@raspberrypi:/home/pi/kompilacje/qt/sql_console# isql -v ms admin haslo
    2. +---------------------------------------+
    3. | Connected! |
    4. | |
    5. | sql-statement |
    6. | help [tablename] |
    7. | quit |
    8. | |
    9. +---------------------------------------+
    10. SQL> quit
    To copy to clipboard, switch view to plain text mode 

    And this is my config file :

    Qt Code:
    1. cat /etc/odbc.ini
    2. [MS]
    3.  
    4. Description = Coeenxion para microsoft sql server
    5. Driver = ms-sql
    6. Servername = ms-sql
    7. UID = admin
    8. Port = 1433
    9.  
    10. cat /etc/odbcinst.ini
    11.  
    12. [ms-sql]
    13. Description = Conexiona microsoft sql server
    14. Driver = /usr/lib/arm-linux-gnueabihf/odbc/libtdsodbc.so
    15. Setup = /usr/lib/arm-linux-gnueabihf/odbc/libtdsS.so
    16. UsageCount = 1
    17. FileUsage = 1
    18.  
    19. root@raspberrypi:/home/pi/kompilacje/qt/sql_console# cat /etc/freetds/freetds.conf
    20. # $Id: freetds.conf,v 1.12 2007/12/25 06:02:36 jklowden Exp $
    21. #
    22. # This file is installed by FreeTDS if no file by the same
    23. # name is found in the installation directory.
    24. #
    25. # For information about the layout of this file and its settings,
    26. # see the freetds.conf manpage "man freetds.conf".
    27.  
    28. # Global settings are overridden by those in a database
    29. # server specific section
    30. [global]
    31. # TDS protocol version
    32. ; tds version = 4.2
    33.  
    34. # Whether to write a TDSDUMP file for diagnostic purposes
    35. # (setting this to /tmp is insecure on a multi-user system)
    36. ; dump file = /tmp/freetds.log
    37. ; debug flags = 0xffff
    38.  
    39. # Command and connection timeouts
    40. ; timeout = 10
    41. ; connect timeout = 10
    42.  
    43. # If you get out-of-memory errors, it may mean that your client
    44. # is trying to allocate a huge buffer for a TEXT field.
    45. # Try setting 'text size' to a more reasonable limit
    46. text size = 64512
    47.  
    48. # A typical Sybase server
    49. [egServer50]
    50. host = symachine.domain.com
    51. port = 5000
    52. tds version = 5.0
    53.  
    54. # A typical Microsoft server
    55. [egServer70]
    56. host = ntmachine.domain.com
    57. port = 1433
    58. tds version = 7.0
    59.  
    60. [ms-sql]
    61. # Version 8.0 para SQL Server 2000
    62. # Version 7.0 para SQL Server 7
    63. # Version 6.0 para SQL Server 6
    64. host = 192.168.7.23
    65. port = 1433
    66. tds version = 8.0
    To copy to clipboard, switch view to plain text mode 

    Do you have any ideas
    Thanks

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Problem with connection to MS SQL on Linux

    Are your SQL plugins located in the right place with respect to your app? See this.

  3. #3
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Problem with connection to MS SQL on Linux

    Try calling setDatabaseName with the DSN you have configured (and the one you used with isql),
    Qt Code:
    1. M_db.setDatabaseName("ms"); // also try "MS"
    2. M_db.setUserName("foo");
    3. M_db.setPassword("bar");
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. DB Connection Problem
    By ktmdwn in forum Qt Programming
    Replies: 13
    Last Post: 4th August 2010, 15:12
  2. SQL Connection Problem
    By Utku in forum Installation and Deployment
    Replies: 3
    Last Post: 25th October 2009, 13:21
  3. Replies: 5
    Last Post: 6th March 2009, 09:58
  4. connection Problem
    By maverick_pol in forum Qt Programming
    Replies: 2
    Last Post: 2nd August 2007, 17:59
  5. SQL connection problem
    By Mrdata in forum Qt Programming
    Replies: 2
    Last Post: 24th May 2007, 19: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.