PDA

View Full Version : Problem with connection to MS SQL on Linux



kprzeb
9th February 2015, 08:17
Hello,
I have Problem with connection to MS SQL on Linux
My code looks like this:

QSqlDatabase m_db;

m_db = QSqlDatabase::addDatabase("QODBC3");
m_db.setDatabaseName("DRIVER={ms};SERVER=192.168.7.23;TDS_VERSION=8.0;PO RT=1433;DATABASE=Hamownia;UID=admin;PWD=haslo;");

qDebug() << "polaczono" << m_db.open();
qDebug() << "DRIVERS :" << QSqlDatabase::drivers();
qDebug() << "error" << m_db.lastError();

if(!m_db.open()){
qDebug()<<"ERROR: "<<QSqlError(m_db.lastError()).text();
} else {
qDebug()<<"Ok";
}


Program replay:

root@raspberrypi:/home/pi/kompilacje/qt/sql_console# ./sql_console
polaczono false
DRIVERS : ("QMYSQL3", "QMYSQL", "QODBC3", "QODBC")
error QSqlError(0, "QODBC3: Unable to connect", "[unixODBC][Driver Manager]Data source name not found, and no default driver specified")
ERROR: "[unixODBC][Driver Manager]Data source name not found, and no default driver specified QODBC3: Unable to connect"


isql connect without any problems:

root@raspberrypi:/home/pi/kompilacje/qt/sql_console# isql -v ms admin haslo
+---------------------------------------+
| Connected! |
| |
| sql-statement |
| help [tablename] |
| quit |
| |
+---------------------------------------+
SQL> quit


And this is my config file :


cat /etc/odbc.ini
[MS]

Description = Coeenxion para microsoft sql server
Driver = ms-sql
Servername = ms-sql
UID = admin
Port = 1433

cat /etc/odbcinst.ini

[ms-sql]
Description = Conexiona microsoft sql server
Driver = /usr/lib/arm-linux-gnueabihf/odbc/libtdsodbc.so
Setup = /usr/lib/arm-linux-gnueabihf/odbc/libtdsS.so
UsageCount = 1
FileUsage = 1

root@raspberrypi:/home/pi/kompilacje/qt/sql_console# cat /etc/freetds/freetds.conf
# $Id: freetds.conf,v 1.12 2007/12/25 06:02:36 jklowden Exp $
#
# This file is installed by FreeTDS if no file by the same
# name is found in the installation directory.
#
# For information about the layout of this file and its settings,
# see the freetds.conf manpage "man freetds.conf".

# Global settings are overridden by those in a database
# server specific section
[global]
# TDS protocol version
; tds version = 4.2

# Whether to write a TDSDUMP file for diagnostic purposes
# (setting this to /tmp is insecure on a multi-user system)
; dump file = /tmp/freetds.log
; debug flags = 0xffff

# Command and connection timeouts
; timeout = 10
; connect timeout = 10

# If you get out-of-memory errors, it may mean that your client
# is trying to allocate a huge buffer for a TEXT field.
# Try setting 'text size' to a more reasonable limit
text size = 64512

# A typical Sybase server
[egServer50]
host = symachine.domain.com
port = 5000
tds version = 5.0

# A typical Microsoft server
[egServer70]
host = ntmachine.domain.com
port = 1433
tds version = 7.0

[ms-sql]
# Version 8.0 para SQL Server 2000
# Version 7.0 para SQL Server 7
# Version 6.0 para SQL Server 6
host = 192.168.7.23
port = 1433
tds version = 8.0



Do you have any ideas
Thanks

d_stranz
9th February 2015, 19:16
Are your SQL plugins located in the right place with respect to your app? See this. (http://doc.qt.io/qt-5/plugins-howto.html)

ChrisW67
10th February 2015, 20:41
Try calling setDatabaseName with the DSN you have configured (and the one you used with isql),


M_db.setDatabaseName("ms"); // also try "MS"
M_db.setUserName("foo");
M_db.setPassword("bar");