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
Related
I tried to connect to MSSQl database using freetds, unixODBC in raspberry pi 4.Below are my settings.
[fred]
host = 109.*.*.* # Remote Sql Server's IP addr
port = 1433 # this is default
tds version = 7.4 # this is by the time i post this
client charset =UTF-8
[test]
Driver = FreeTDS
Description = MSSQL Server
Trace = No
Server = fred # IP or host name of the Sql Server
Port = 1433 # This is default
TDS_Version = 7.4
[FreeTDS]
Description=FreeTDS Driver
Driver=/usr/lib/arm-linux-gnueabihf/odbc/libtdsodbc.so
Setup=/usr/lib/arm-linux-gnueabihf/odbc/libtdsS.so
UsageCount=1
I have tested with tsql -H ip -U username -P password but the error still persists. I have also installed pyodbc. I am trying to connect from Pi to MS SQl Server Management studio. Could anyone suggest me to have a successful connection to database? I appreciate all the approaches.
I was able to shrug off this error by using the following call:
bsqldb -S $servername:1433 -D $databasename -U $username -P $password -i $inputfile
As far as documentation states, a qualified server name with the port number allows to bypass the related .conf settings.
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 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!
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.
While trying to connect remote SQL Server:
$tsql -S localhost -U myuser
I got error like:
locale is "en_US.UTF-8"
locale charset is "UTF-8"
using default charset "UTF-8"
Error 20009 (severity 9):
Unable to connect: Adaptive Server is unavailable or does not exist
OS error 61, "Connection refused"
There was a problem connecting to the server
The output of $tsql -C is as below:
Compile-time settings (established with the "configure" script)
Version: freetds v0.91
freetds.conf directory: /usr/local/freetds/conf/freetds
MS db-lib source compatibility: no
Sybase binary compatibility: no
Thread safety: yes
iconv library: no
TDS version: 5.0
iODBC: no
unixodbc: no
SSPI "trusted" logins: no
Kerberos: no
I have created tunnel for remote server like:
$ssh -L 1433:db_server:1433 user#mid_server
This forward the local port 1433 to db_server. I tested. My ssh tunnel works because I can connect to database using Navicat (localhost on 1433). I can telnet localhost on port 1433.
I kinda get it worked by modifying freetds.conf
from
[global]
# TDS protocol version
; tds version = 4.2
to
[global]
# TDS protocol version
tds version = 7.0
This worked for me with ASE 16.0 installed and running on Ubuntu 14.04 LTS, both client and server.
SERVER: Make sure there is an entry in /etc/hosts of your server (sybaseServer). In a standard Ubuntu 14.04 installation you will not find this, but "127.0.1.1 sybaseServer". But sybase seems depends on it.
/etc/hosts
...
192.168.1.100 sybaseServer
...
CLIENT: The entry in freetds.conf is
[SYBASE]
host = 192.168.1.100
port = 5000
tds version = 5.0
Now you can connect to your server:
$tsql -S SYBASE -U sa
obviously you have to replace IP-address, servername etc. with your own data