ubuntu tsql working and isql not working - sql-server

I'm trying to connect MSSQL server to ubuntu 14.04 with FreeTDS and unixODBC.
I can connect using tsql with:
~$ tsql -S MSSQL -U <username> -P <password>
This works correctly.
When trying to use isql i get the following
isql -v MSSQL <username> <password>
[S1000][unixODBC][FreeTDS][SQL Server]Unable to connect to data source
[ISQL]ERROR: Could not SQLConnect
Here are my configs.
odbc.ini
[MSSQL]
Driver = FreeTDS
TDS_Version = 8.0
Server = <server>
Instance = dev
Database = <database>
odbcinst.ini
[FreeTDS]
Description = FreeTDS
Driver = /usr/local/lib/libtdsodbc.so
Setup = /usr/local/lib/libtdsodbc.so
Trace = Yes
TraceFile = /tmp/freetds.log
ForceTrace = Yes
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
[MSSQL]
host = <host>
instance = dev
tds version = 8.0
I think the issue is being caused by the driver, I don't believe i should get an error saying the driver isn't executable. here is the osql output:
osql -S MSSQL -U <username> -P <password>
checking shared odbc libraries linked to isql for default directories...
strings: '': No such file
trying /tmp/sql ... no
trying /tmp/sql ... no
trying /etc ... OK
checking odbc.ini files
reading /home/<user>/.odbc.ini
[MSSQL] found in /home/<user>/.odbc.ini
found this section:
[MSSQL]
Driver = FreeTDS
TDS_Version = 8.0
Server = <server>
Database = <database>
looking for driver for DSN [MSSQL] in /home/<user>/.odbc.ini
found driver line: " Driver = FreeTDS"
driver "FreeTDS" found for [MSSQL] in .odbc.ini
found driver named "FreeTDS"
"FreeTDS" is not an executable file
looking for entry named [FreeTDS] in /etc/odbcinst.ini
found driver line: " Driver = /usr/local/lib/libtdsodbc.so"
found driver /usr/local/lib/libtdsodbc.so for [FreeTDS] in odbcinst.ini
/usr/local/lib/libtdsodbc.so is an executable file
"Server" found, not using freetds.conf
Server is <server_name>
Configuration looks OK. Connection details:
DSN: MSSQL
odbc.ini: /home/<user>/.odbc.ini
Driver: /usr/local/lib/libtdsodbc.so
Server hostname: <host>
Address: <ip_address>
Attempting connection as <username> ...
+ isql MSSQL <username> <password> -v
[S1000][unixODBC][FreeTDS][SQL Server]Unable to connect to data source
[ISQL]ERROR: Could not SQLConnect
Any help is appreciated, Thanks.

I found the answer to my question. I needed to add the instance to the server in the odbc.ini file like so
MSSQL]
Driver = FreeTDS
TDS_Version = 8.0
Server = <server\dev>
Database = <database>
This let me execute isql.

Related

MAC OSX - How to solve "Could not SQLConnect" error

I'm trying to connect to my sql server database but it's not working.
The freetds is working, see the command:
tsql -S myserver.database.windows.net -U myuser -P mypassword
output:
locale is "C/UTF-8/C/C/C/C"
locale charset is "UTF-8"
using default charset "UTF8"
1>
but when I try to run the command isql, it returns me error.
command:
isql -v MYSERVER myuser mypassword
output:
[IM002][unixODBC][Driver Manager]Data source name not found, and no default driver specified
[ISQL]ERROR: Could not SQLConnect
My files:
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 = 8.0
# 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
# If you experience TLS handshake errors and are using openssl,
# try adjusting the cipher list (don't surround in double or single quotes)
# openssl ciphers = HIGH:!SSLv2:!aNULL:-DH
[MYSERVER]
host = myserver.database.windows.net
port = 1433
tds version = 8.0
client charset = UTF8
odbcinst.ini:
[FreeTDS]
Description = FreeTDS
Driver = /usr/local/lib/libtdsodbc.so
Setup = /usr/local/lib/libtdsodbc.so
UsageCount = 1
Trace = Yes
TraceFile = /Users/giorgecaique/Documents/sql.log
odbc.ini:
[MYSERVER]
Description = MYSERVER
Driver = FreeTDS
Database = mydatabase
Server = myserver.database.windows.net
UserName = myuser
Password = mypassword
TDS_Version = 8.0
Can anyone help me? I already saw a lot of tutorials of how to solve this, but none of it worked for me.
In odbc.ini file, you need a Servername attribute which points to the name of the DSN in freetds.conf. Also, 8.0 is not a valid version (long story, see the docs), and it is UTF-8 not UTF8. For example:
freetds.conf:
[MYSERVER]
host = myserver.database.windows.net
port = 1433
tds version = 7.1
client charset = UTF-8
And then in odbc.ini:
[MYSERVER]
Description = MYSERVER
Driver = FreeTDS
Database = mydatabase
Servername = MYSERVER
UserName = myuser
Password = mypassword
TDS_Version = 7.1
Good luck!
Have you checked that you have the library /usr/local/lib/libtdsodbc.so?
I ran into a similar error. I fixed my error following this guide at link.
I believe you may not have installed the drivers for freetds, which you can install via Homebrew with:
$ brew install freetds --with-unixodbc
Did you try emehex's answer from here:
Can't open lib 'ODBC Driver 13 for SQL Server'? Sym linking issue?
sudo ln -s /usr/local/etc/odbcinst.ini /etc/odbcinst.ini
sudo ln -s /usr/local/etc/odbc.ini /etc/odbc.ini

Connect to MSSQL database with arm linux board using unixODBC and FreeTDS problems

I am having problems to query a remote MSSQL database from my arm linux board.
I compiled unixODBX and FreeTDS, copied all files to the arm board with the same path as in the Ubuntu machine where they where compiled.
I also compiled everything for the Ubuntu machine.
In the Ubuntu machine I can connect and query the database with tsql and isql.
In the arm board I can only connect and query with tsql, not with isql.
COMPILATION FOR THE ARM BOARD IN THE UBUNTU MACHINE:
unixODBX:
./configure --prefix=/usr/local/unixodbc-arm --host=arm-linux
make
make install
I removed /usr/local/unixodbc-arm/bin/odbc_config otherwise I couldĀ“t compile it.
FreeTDS:
./configure --prefix=/usr/local/freetds-arm --with-unixodbc=/usr/local/unixodbc-arm --host=arm-linux --disable-libiconv
make
make all
I used --disable-libiconv because without this option was not working.
Than I copied the files in the "bin", "lib" and "etc" directories to the arm board with the same path as in the Ubuntu machine.
/usr/local/unixodbc-arm/bin
/usr/local/unixodbc-arm/lib
/usr/local/unixodbc-arm/etc
/usr/local/freetds-arm/bin
/usr/local/freetds-arm/lib
/usr/local/freetds-arm/etc
The configuartion files are as follows:
freetds.conf:
root#ok335x:/# cat /usr/local/freetds-arm/etc/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 on a multi-user system
# 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
# Microsoft SQL Server
[SQLEXPRESS]
host = 192.168.0.195
port = 1433
tds version = 7.0
client charset = UTF-8
root#ok335x:/#
odbcinst.ini:
root#ok335x:/# cat /usr/local/unixodbc-arm/etc/odbcinst.ini
[FreeTDS]
Description=TDS driver (Sybade/MS SQL)
Driver=/usr/local/freetds-arm/lib/libtdsodbc.so
UsageCount=2
root#ok335x:/#
odbc.ini
root#ok335x:/# cat /usr/local/unixodbc-arm/etc/odbc.ini
[SQLEXPRESS]
Description = Test to FreeTDS
Driver = FreeTDS
Trace = Yes
TraceFile = sql.log
Database = gti
Servername = SQLEXPRESS
UserName = gti_monitor
Password = gti_monitor
Port = 1433
ReadOnly = No
RowVersioning = No
ShowSystemTables = No
ShowOidColumn = No
FakeOidIndex = No
ConnSettings =
root#ok335x:/#
tsql configuration:
root#ok335x:/# tsql -C
Compile-time settings (established with the "configure" script)
Version: freetds vdev.0.99.134
freetds.conf directory: /usr/local/freetds-arm/etc
MS db-lib source compatibility: no
Sybase binary compatibility: no
Thread safety: yes
iconv library: no
TDS version: 5.0
iODBC: no
unixodbc: yes
SSPI "trusted" logins: no
Kerberos: no
OpenSSL: no
GnuTLS: no
root#ok335x:/#
odbcinst configuration:
root#ok335x:/# odbcinst -j
unixODBC 2.3.4
DRIVERS............: /usr/local/unixodbc-arm/etc/odbcinst.ini
SYSTEM DATA SOURCES: /usr/local/unixodbc-arm/etc/odbc.ini
FILE DATA SOURCES..: /usr/local/unixodbc-arm/etc/ODBCDataSources
USER DATA SOURCES..: /home/root/.odbc.ini
SQLULEN Size.......: 4
SQLLEN Size........: 4
SQLSETPOSIROW Size.: 2
root#ok335x:/#
Running tsql:
root#ok335x:/# tsql -S SQLEXPRESS -U gti_monitor -P gti_monitor
locale is "C"
locale charset is "ANSI_X3.4-1968"
using default charset "UTF-8"
1> select * from pressures
2> go
id datetime press1 press2
NULL NULL 1 2
(1 row affected)
1> quit
root#ok335x:/#
Running isql:
root#ok335x:/# isql SQLEXPRESS gti_monitor gti_monitor -v
[S1000][unixODBC][FreeTDS][SQL Server]Unable to connect to data source
[ISQL]ERROR: Could not SQLConnect
root#ok335x:/#
These commands are both working in the Ubuntu machine with the same configuration files.
Can anyone help on that?
Thank you very much.
From the isql man page...
isql DSN [USER [PASSWORD]] [options]
DSN. The Data Source Name, which should be used to make connection to the database. The data source is looked for in the /etc/odbc.ini and $HOME/.odbc.ini files in that order, with the latter overwriting the former.
Tsql with -S is using your freetds.conf file. But it looks like you have the odbc.ini file in /usr/local/unixodbc-arm/etc/odbc.ini

FreeTDS can't read Servername from odbc.ini

I am trying to setup FreeTDS to connect into a mssql server in Ubuntu 14.04 and FreeTDS 4.2
However osql can't read Servername setting due unknow reasons.
If I use isql, it works. However my programs use odbc.ini settings.
What I am doing wrong?
My odbc.ini;
[ODBC Data Sources]
Test = My Test Server
[mssql]
Description = My Test Server
Driver = FreeTDS
Trace = No
TDS_Version = 4.2
Servername = mssql
Command
~$ osql -S mssql -U user -P password
checking shared odbc libraries linked to isql for default directories...
strings: '': No hay tal fichero
trying /tmp/sql ... no
trying /tmp/sql ... no
trying /etc ... OK
checking odbc.ini files
reading /home/business/.odbc.ini
[mssql] not found in /home/business/.odbc.ini
reading /etc/odbc.ini
[mssql] found in /etc/odbc.ini
found this section:
[mssql]
Description = My Test Server
Driver = FreeTDS
Trace = No
TDS_Version = 4.2
Servername = mssql
looking for driver for DSN [mssql] in /etc/odbc.ini
found driver line: " Driver = FreeTDS"
driver "FreeTDS" found for [mssql] in odbc.ini
found driver named "FreeTDS"
"FreeTDS" is not an executable file
looking for entry named [FreeTDS] in /etc/odbcinst.ini
found driver line: " Driver = /usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so"
found driver /usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so for [FreeTDS] in odbcinst.ini
/usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so is an executable file
Using ODBC-Combined strategy
DSN [mssql] has servername "" (from /etc/odbc.ini)
A few things you'll want to fix up here. First, in odbc.ini, is it "Server" and not "Servername". Here's an example.
odbc.ini:
[myserver]
Driver = FreeTDS
Server = myserver.mydomain.com
Port = 1433
TDS_Version = 7.2
freetds.conf:
[myserver]
host = myserver.mydomain.com
port = 1433
tds version = 7.2
Also, you're going to want to use a higher TDS Version. TDS 4.2 was for Microsoft SQL Server 6.0! Despite the documentation, I have found it does not work with all products. To select an appropriate TDS version, see here:
http://www.freetds.org/userguide/choosingtdsprotocol.htm
You most likely want version 7.2 or 7.3. Good luck!

"Unknown host machine name." on FreeBSD + unixODBC + FreeTDS

I got some issues connecting to a Microsoft SQL Server 2012 from my FreeBSD 10.1 server.
I installed FreeTDS and unixODBC via ports. I compiled FreeTDS with unixODBC support. This ist my freetds.conf:
[server1]
host = 192.168.100.147
port = 1433
tds version = 7.2
Invoking tsql works fine.
But when i try to connect via odbc with "osql" or "isql" the connection failes with the following error:
checking shared odbc libraries linked to isql for default directories...
trying /tOH ... no
trying /tOH ... no
trying /tmp/sqlH ... no
trying /tmp/sqlH ... no
trying /usr/locH ... no
trying /usr/locH ... no
trying /tmp/sql.log ... no
trying /home ... no
trying /.odbc.ini ... no
trying /usr/local/etc ... OK
checking odbc.ini files
reading /root/.odbc.ini
[server1] not found in /root/.odbc.ini
reading /usr/local/etc/odbc.ini
[server1] found in /usr/local/etc/odbc.ini
found this section:
[server1]
Driver = FreeTDS
Servername = server1
looking for driver for DSN [server1] in /usr/local/etc/odbc.ini
found driver line: " Driver = FreeTDS"
driver "FreeTDS" found for [server1] in odbc.ini
found driver named "FreeTDS"
"FreeTDS" is not an executable file
looking for entry named [FreeTDS] in /usr/local/etc/odbcinst.ini
found driver line: " Driver = /usr/local/lib/libtdsodbc.so"
found driver /usr/local/lib/libtdsodbc.so for [FreeTDS] in odbcinst.ini
/usr/local/lib/libtdsodbc.so is an executable file
Using ODBC-Combined strategy
DSN [server1] has servername "server1" (from /usr/local/etc/odbc.ini)
cannot read "/root/.freetds.conf"
/usr/local/etc/freetds/freetds.conf is a readable file
looking for [server1] in /usr/local/etc/freetds/freetds.conf
found this section:
[server1]
host = 192.168.100.147
port = 1433
tds version = 7.2
looking up hostname for ip address 192.168.100.147
Configuration looks OK. Connection details:
DSN: server1
odbc.ini: /usr/local/etc/odbc.ini
Driver: /usr/local/lib/libtdsodbc.so
Server hostname: sqlsrv01
Address: 192.168.100.147
Attempting connection as sa ...
+ isql server1 sa foobar -v
[S1000][unixODBC][FreeTDS][SQL Server]Unable to connect to data source
[01000][unixODBC][FreeTDS][SQL Server]Unknown host machine name.
[ISQL]ERROR: Could not SQLConnect
This is the content of my odbc.ini:
[server1]
Driver = FreeTDS
Servername = server1
And this is my odbcinst.ini:
[FreeTDS]
Driver = /usr/local/lib/libtdsodbc.so
Client Charset = UTF-8
UsageCount = 1
I read severeal posts regarding to using the exact naming inf odbc.ini and freetds.conf, but the connection keeps failing.
Can anybody help?
I'm now able to answer my own question.
Following a hint from the unixODBC mailinglist Link I invoked
odbcinst -i -s -f /usr/local/etc/odbc.ini
and now I am able to connect to the server via osql.

freeTDS not using its config

I've decided to use FreeTDS driver and unixODBC to manage the PDO connection between my LAMP-based app with a remote MsSQL database.
unfortunately it appears that the driver doesn't read the freetds.conf file, nor the environmental variables set either directly via server's CLI or specified in php file by putenv() function.
now some data:
as I ping the server - no packets are lost.
as I telnet the server on 1433 port - the connection is established
as I use the command
TDSVER=7.0 tsql -H >IP< -p 1433 -U username
I am prompted to enter password and connection is established.
without the TDSVER preceding the command - the connection fails with such a message:
Error 20017 (severity 9):
Unexpected EOF from the server
OS error 115, "Operation now in progress"
Error 20002 (severity 9):
Adaptive Server connection failed
There was a problem connecting to the server
the tsql -C commands echos such an output:
Compile-time settings (established with the "configure" script)
Version: freetds v0.91
freetds.conf directory: /usr/local/etc
MS db-lib source compatibility: yes
Sybase binary compatibility: no
Thread safety: yes
iconv library: yes
TDS version: 5.0
iODBC: no
unixodbc: yes
SSPI "trusted" logins: no
Kerberos: no
freetds.conf in the location given above has this entry:
[MSSQL]
host = >IP<
port = 1433
tds version = 7.0
the ISQL also fails:
isql -v MSSQL
[S1000][unixODBC][FreeTDS][SQL Server]Unable to connect to data source
[01000][unixODBC][FreeTDS][SQL Server]Adaptive Server connection failed
[ISQL]ERROR: Could not SQLConnect
my odbc.ini :
[MSSQL]
Description = MS SQL Server
Driver = FreeTDS
TDS_Version = 7.0
Server = >IP<
UID = username
PWD = password
ReadOnly = No
Port = 1433
I suppose the solution is really simple, but i'm just too stupid to find it...
I spent a long time today debugging a similar problem. I had set "TDS version" in freetds.conf but it was not being used in my ODBC connection. After reading the freetds source code (connectparams.c:odbc_parse_connect_string) I discovered that:
If your connection string uses "SERVER=" then both freetds.conf and odbc.ini are ignored
If your connection string uses "SERVERNAME=" then the settings in the appropriate freetds.conf server are used
If your connection string uses "DSN=" then the settings in the appropriate odbc.ini DSN are used
odbcinst.ini is a red herring. FreeTDS never checks that for settings.
The settings you specify in the connection string are always respected. It also always respects the environment variables like TDSVER.
My gut instinct is you need to change your tds version = 7.0 to tds version = 8.0 in your freetds.conf and odbc.ini files AND you need something in your odbcinst.ini file. Here's what I've got working on an Ubuntu 12.04 server talking to a remote MSSQL server:
freetds.conf
# Define a connection to the MSSQL server.
[mssql]
host = myserver
port = 1433
tds version = 8.0
odbc.ini
# Define a connection to the MSSQL server.
# The Description can be whatever we want it to be.
# The Driver value must match what we have defined in /etc/odbcinst.ini
# The Database name must be the name of the database this connection will connect to.
# The ServerName is the name we defined in /etc/freetds/freetds.conf
# The TDS_Version should match what we defined in /etc/freetds/freetds.conf
[mssql]
Description = MSSQL Server
Driver = freetds
Database = MyDB
ServerName = myserver
TDS_Version = 8.0
odbcinst.ini
# Define where to find the driver for the Free TDS connections.
[freetds]
Description = MS SQL database access with Free TDS
Driver = /usr/lib/i386-linux-gnu/odbc/libtdsodbc.so
Setup = /usr/lib/i386-linux-gnu/odbc/libtdsS.so
UsageCount = 1
I experienced this exact same problem, but my config was already correctly set up. The problem was that the TDS versions that freetds.conf recognizes has changed in newer versions, but apparently the old versions still work in the TDSVER environment variable. Once I set the version in the config files to 7.1 rather than 8.0 everything started working.
The initial TDSVER=7.0 issue was resolved by adding the following at the end of my odbc.ini file:
[Default]
Driver=/usr/local/lib/libtdsodbc.so
Instead of connecting to an IP, try to connect to the name of the configuration section? For example:
isql -v MSSQL

Resources