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!
Related
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
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.
I am trying to connect to MSSQL server from Ubuntu. I have installed freetds like suggested here.
However, when I try to configure /etc/odbc.ini and enter a driver path I have no driver at location /usr/local/freetds/lib/libtdsodbc.so.
Can someone help me to install freetds and to configure odbc to use it?
*edit1: I have found libtdsodbc.so in /usr/lib/x86_64-linux-gnu/odbc. Should I use that driver/path?
I've created a Vagrant box which has a full installation example here: https://github.com/FlipperPA/django-python3-vagrant/
...but here are the basic steps.
# Install pre-requesite packages
sudo apt-get install unixodbc unixodbc-dev freetds-dev freetds-bin tdsodbc
Point odbcinst.ini to the driver in /etc/odbcinst.ini:
[FreeTDS]
Description = v0.91 with protocol v7.2
Driver = /usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so
Create your DSNs in odbc.ini:
[dbserverdsn]
Driver = FreeTDS
Server = dbserver.domain.com
Port = 1433
TDS_Version = 7.2
...and your DSNs in freetds.conf:
[global]
# TDS protocol version, use:
# 7.3 for SQL Server 2008 or greater (tested through 2014)
# 7.2 for SQL Server 2005
# 7.1 for SQL Server 2000
# 7.0 for SQL Server 7
tds version = 7.2
port = 1433
# 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 Microsoft server
[dbserverdsn]
host = dbserver.domain.com
port = 1433
tds version = 7.2
After completing this, you can test your connection by attempting to connect with tsql (to test the FreeTDS layer) and isql (for the unixODBC through FreeTDS stack).
The version available via apt-get is a really old version. To get a newer version:
sudo apt-get install wget
sudo apt-get install build-essential
sudo apt-get install libc6-dev
# find latest version of FreeTDS ftp://ftp.freetds.org/pub/freetds/stable/
wget ftp://ftp.freetds.org/pub/freetds/stable/freetds-1.2.tar.gz
tar -xzf freetds-1.2.tar.gz
cd freetds-1.2
./configure --prefix=/usr/local --with-tdsver=7.3
sudo make
sudo make install
in freedts.conf
[Server80]
host = example.com
port = 1433
tds version = 8.0
client charset = UTF-8
in odbc.ini
[MSSQL8]
Driver = FreeTDS
Description = Sybase JDBC Server
Trace = No
Servername = Server80
Database = DBNAME
UID = sa
ClientCharset = UTF-8
in odbcinst.ini
[FreeTDS]
Description=v0.63 with protocol v8.0
Driver=/usr/lib/i386-linux-gnu/odbc/libtdsodbc.so
UsageCount=2
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.
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