freetds version isn't changing, while file is changed - sql-server

I have a freetds installation at my linux machine
when i check the tds version using tsql -C
Compile-time settings (established with the "configure" script)
Version: freetds v0.91
freetds.conf directory: /etc
MS db-lib source compatibility: yes
Sybase binary compatibility: yes
Thread safety: yes
iconv library: yes
TDS version: 4.2
iODBC: no
unixodbc: yes
SSPI "trusted" logins: no
Kerberos: yes
however in my /etc/freetds.conf i have set the TDS Version to 8.0
[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
tds version = 8.0
port = 1433
client charset = UTF-8
debug flags = 0x4fff
timeout = 180
connect timeout = 180
text size = 20971520
I really need it to be set to 8.0, because I am facing this issue while running my sql queries from a linux end point
"Unicode data in a Unicode-only collation or ntext data cannot be sent to clients using DB-Library"
And one of the only fixes i see suitable is to mark the tds version as 8.0 and set the charset to UTF-8

I should have also changed the tds version at the odbc.ini file with param
TDS_Version = 8.0
I took a cue from here freeTDS not using its config

Related

Connect to MS SQL Server Database Using isql on Mac

Summary: tsql connects and isql doesn't.
Details: I have tried every official installation guide and Stack Overflow question I can find, but none of them produce joy. I'm trying to connect to a MS SQL Server database from my Mac (Mohave), and ultimately a Xubuntu 16.04 virtual machine as well, using pyodbc. Before getting into the Python, I just want to trouble-shoot the connection. The problem is, most of the documentation I'm seeing is missing important details such as, "Should I use quotes in usernames and passwords?" Or, "Should I include the domain in the username?" And if I should include the domain the username, "Should I escape the backslash character?"
Here is my current setup: tsql -C produces
Compile-time settings (established with the "configure" script)
Version: freetds v1.1.11
freetds.conf directory: /usr/local/etc
MS db-lib source compatibility: no
Sybase binary compatibility: yes
Thread safety: yes
iconv library: yes
TDS version: 7.3
iODBC: no
unixodbc: yes
SSPI "trusted" logins: no
Kerberos: yes
OpenSSL: yes
GnuTLS: no
MARS: yes
The contents of /usr/local/etc/freetds.conf are:
#
# 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 = auto
# 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
# To reduce data sent from server for BLOBs (like TEXT or
# IMAGE) try setting 'text size' to a 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
# A typical Sybase server
[egServer50]
host = symachine.domain.com
port = 5000
tds version = 5.0
# A typical Microsoft server
[egServer73]
host = ntmachine.domain.com
port = 1433
tds version = 7.3
[my_server]
host = my_server
port = 1433
tds version = 7.3
The my_server is the server to which I'm trying to connect.
The command tsql -S my_server -U domain\\username -P password, with no quotes anywhere, connects just fine, with the result
locale is "en_US.UTF-8"
locale charset is "UTF-8"
using default charset "UTF-8"
1>
So much for FreeTDS. For the ODBC side, first note that FreeTDS is apparently already set up for ODBC, as it says unixodbc: yes in the results of tsql -C. My /etc/odbcinst.ini file contains:
[FreeTDS]
Description=FreeTDS Driver for Linux & MSSQL
Driver=/usr/local/lib/libtdsodbc.so
Setup=/usr/local/lib/libtdsodbc.so
UsageCount=1
My /etc/odbc.ini file contains
[my_server]
Description = "The Location of the EOAM_RA Database"
Driver = FREETDS
Trace = Yes
TraceFile = /tmp/sql.log
Database = my_database
Servername = my_server
UserName = domain\\username
Password = password
Port = 1433
Protocol = 7.3
ReadOnly = No
RowVersioning = No
ShowSystemTables = No
ShowOidColumn = No
FakeOidIndex = No
But when I try any version of isql -v my_server username password, I get the dreaded and incredibly unhelpful
[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
So, while I certainly would LOVE to have the right settings for everything so that I can connect via isql and ultimately pyodbc, it would also help greatly if I could have the answers to the following questions:
For every place where I should have my username typed in, should it have quotes around it?
For every place where I should have my username typed in, should I have it prefixed with the domain?
For every place where I should have my username typed in, if I do need my domain included, should I escape the backslash in-between?
For servers, should I include quotes?
Many thanks for your time!
Have you tried connecting after using the fully qualified domain name (fqdn) for your SQL Server in the freetds.conf file:
[my_server]
host = my_server.<yourdomain.example>
port = 1433
tds version = 7.3

freetds not recognizing version from any config files

Not sure why...
I have the same conf file in /etc/freetds/freetds.conf, in /usr/share/freetds/freetds.conf and ~/.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 = 7.4
# 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
[cdcods]
host = *my_host*
port = 1433
tds version = 7.4
Where my_host is my actual mssql host. I'm connecting to a MSSQL 2012 so 7.4 is correct I think.
The command I'm using is $tsql -S cdcods -U 'my_domain\my_user' -P 'my_pass'
Here's the log:
log.c:196:Starting log file for FreeTDS 0.91
on 2017-02-03 13:20:19 with debug flags 0x4fff.
iconv.c:330:tds_iconv_open(0x15749f0, UTF-8)
iconv.c:187:local name for ISO-8859-1 is ISO-8859-1
iconv.c:187:local name for UTF-8 is UTF-8
iconv.c:187:local name for UCS-2LE is UCS-2LE
iconv.c:187:local name for UCS-2BE is UCS-2BE
iconv.c:349:setting up conversions for client charset "UTF-8"
iconv.c:351:preparing iconv for "UTF-8" <-> "UCS-2LE" conversion
iconv.c:391:preparing iconv for "ISO-8859-1" <-> "ISO-8859-1" conversion
iconv.c:394:tds_iconv_open: done
net.c:207:Connecting to *my_host* port 1433 (TDS version 4.2)
net.c:272:tds_open_socket: connect(2) returned "Operation now in progress"
net.c:312:tds_open_socket() succeeded
util.c:156:Changed query state from DEAD to IDLE
login.c:572:NT login not support using TDS 4.x or 5.0
util.c:156:Changed query state from IDLE to DEAD
util.c:331:tdserror(0x15749c0, 0x15749f0, 20002, 0)
util.c:361:tdserror: client library returned TDS_INT_CANCEL(2)
util.c:384:tdserror: returning TDS_INT_CANCEL(2)
mem.c:615:tds_free_all_results()
You're running FreeTDS v0.91 which does not support TDS version 7.4. IIRC the highest it supports is 7.2. Trying using version 7.2.
If you want to use TDS version 7.3, you'll need at least FreeTDS 0.95, and if you want 7.4, you'll need FreeTDS 1.0.
I have a PR to clarify this, but it hasn't been pushed out to the documentation.
Good luck!

pyodbc not working on RedHat 5.4. Trying to connect to ms-sql database server using unixODBC and FreeTDS?

I am facing issue while trying to access ms-sql database using pyobdc.
Here is the System config:
Python 2.7.11
Pyodbc 3.0.7
RedHat 5.4 (Tikanga) 32 Bit system
Microsoft SQL Server 2012 (Database server)
unixODBC 2.3.0
$ tsql -C output :
Compile-time settings (established with the "configure" script)
Version: freetds v0.91
freetds.conf directory: /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
$ odbcinst -j output :
unixODBC 2.3.0
DRIVERS............: /usr/local/etc/odbcinst.ini
SYSTEM DATA SOURCES: /usr/local/etc/odbc.ini
FILE DATA SOURCES..: /usr/local/etc/ODBCDataSources
USER DATA SOURCES..: /root/.odbc.ini
SQLULEN Size.......: 4
SQLLEN Size........: 4
SQLSETPOSIROW Size.: 2
$ cat /usr/local/etc/odbcinst.ini output :
[ms-sql]
Description=TDS connection
Driver=/usr/local/lib/libtdsodbc.so
Setup=/usr/local/lib/libtdsodbc.so
FileUsage=1
UsageCount=1
$ cat /usr/local/etc/odbc.ini output :
[sqlserverdatasource]
Driver = ms-sql
Description = ODBC connection via ms-sql
Trace = No
Server = >IP Addresss To Database server<
Port = >Port Number<
Database = >Database name<
$ cat /etc/freetds.conf output :
[sql-server]
host = >IP Addresss To Database server<
port = >Port Number<
tds version = 8.0
Command which is giving me error:
connection = pyodbc.connect(r'DRIVER={FreeTDS};SERVER=>IP Addresss To Database server<; PORT=>Port Number<;DATABASE=Database name;UID=Database UID;PWD=DatabasePasswd;')
Error:
Traceback (most recent call last): File "<stdin>", line 1, in
<module> pyodbc.Error: ('IM002', '[IM002] [unixODBC][Driver
Manager]Data source name not found, and no default driver specified
(0) (SQLDriverConnect)')
I am trying to solve this problem for last 3 days. But no luck yet. So any help/suggestion would be very helpful.
I have already gone through googling.
Thanks in advance :)
Try something like this:
freetds.conf:
[sql-server]
host = sql-server.host.com
port = 1433
tds version = 7.2
odbc.ini:
[sql-server]
Driver = FreeTDS
Server = sql-server.host.com
Port = 1433
TDS_Version = 7.2
odbcinst.ini:
[FreeTDS]
Description = v0.91 with protocol v7.2
Driver = /usr/local/lib/libtdsodbc.so
In Python:
connection = pyodbc.connect(r'DRIVER={FreeTDS};SERVER=sql-server.host.com;PORT=1433;DATABASE=Database name;UID=Database Username;PWD=DatabasePasswd;TDS_Version=7.2')
TDS Version 8.0 does not exist. 7.2 is the highest supported in FreeTDS 0.91. See here to explain the confusion: http://www.freetds.org/userguide/choosingtdsprotocol.htm
If you're still having issues, try testing with tsql and isql to test the FreeTDS and unixODBC layers of the connection stack respectively. Good luck!

tsql connects to ODBC but Perl DBI gets an error

Client is Ubuntu 14.04.1 LTS talking to an MS SQL Server 2005. Ubuntu has no registered domain. It's inside the local network as is the MS SQL Server.
Perl 5.18.2 using DBI 1.63 and DBD::ODBC 1.52.
Installed FreeTDS 0.92 (with TDS v4.2) and unixODBC 2.2.14.
isql DSN USERNAME PASSWD at the command line also doesn't work. Perhaps I should start with that. I still get the same error which is Unable to connect to data source (SQL-08001).
My related config files:
2015-07-09 11:55:14 AM
NOTE: TDS version from tsql -C must go into freetds.conf and odbc.ini files
=========================================
/etc/odbcinst.ini:
[FreeTDS]
Description = FreeTDS 0.91 for Microsoft SQL Server 2005
#Driver = /usr/lib/odbc/libtdsodbc.so
Driver = /usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so
Setup = /usr/lib/x86_64-linux-gnu/odbc/libtdsS.so
UsageCount = 1
#Threading = 2
fileusage = 1
dontdlclose = 1
=========================================
/etc/odbc.ini:
[ODBC Data Sources]
ResponseBDO = Response database desc in /etc/odbc/ini
[FreeTDS]
Description = FreeTDS 0.91 driver
Driver = /usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so
[responsebdo]
Driver = FreeTDS
Description = Response MSSQL 2005 ODBC driver
SERVER = sqlsvr.mydomain.com
PORT = 1433
USER = 'domain\domainuser'
Password = mypasswd
Database = r4w_004
# TDS_VERSION should be same as reported by 'tsql -C'.
TDS_Version = 4.2
[Default]
Driver = /usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so
Description = Default FreeTDS ODBC driver
SERVER = 10.20.30.40
USER = "domain\domainuser"
Database = r4w_4
=========================================
Relevant part of /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".
#
[responsetds]
#host = 10.20.30.40
host = sqlsvr.mydomain.com
port = 1433
tds version = 4.2
connect timeout = 20
timeout = 20
dump file = /tmp/freetds-resp.log
instance = MSSQLSERVER
use ntlmv2 = yes
=========================================
tsql -C:
Compile-time settings (established with the "configure" script)
Version: freetds v0.91
freetds.conf directory: /etc/freetds
MS db-lib source compatibility: no
Sybase binary compatibility: yes
Thread safety: yes
iconv library: yes
TDS version: 4.2
iODBC: no
unixodbc: yes
SSPI "trusted" logins: no
Kerberos: yes
=========================================
odbcinst --version:
unixODBC 2.2.14
Perl connection info:
$respdsn="dbi:ODBC:Driver={SQL Native Client};Server=10.20.30.40;".
"UID=$respdbuser;PWD=$respdbpw;Database=r4w_004";
$respdbh=DBI->connect($respdsn);
I can connect to the database by using tsql at the command line.
But using Perl I get this error:
DBI connect('Driver={SQL Native Client};Server=10.19.1.3;UID=gilson\mwreports;PWD=MR4gilson;Database=r4w_004','',...) failed:
[unixODBC][Driver Manager]Data source name not found, and no default
driver specified (SQL-IM002) at /home/chuck/perl/gilson/jimv/fedex/fedex.pl line 1557.
at /usr/lib/perl5/DBI.pm line 691.
DBI::__ANON__[/usr/lib/perl5/DBI.pm:744](undef, undef) called at /usr/lib/perl5/DBI.pm line 747
My questions:
Is the "{SQL Native Client}" in the Perl connection string correct? Does it refer to an entry in the odbc.ini or freetds.conf file?
What am I missing here?
Thank you.
If you're using FreeTDS, then your Driver is FreeTDS not "Sql Native Client".
Try this line to get your database handle:
my $dbh = DBI->connect("dbi:ODBC:Driver=FreeTDS;Server=10.20.30.40;database=r4w_004", $respdbuser, $respdbpw);
I had the same problem, when I using tsql works normally but using perl with dbi didn't. I lost many hours trying to figure out the problem, so I saw the limitations of Adaptive Server:
The name cannot be more than 30 characters long.
The first character must be a letter (ASCII a through z, A through Z).
The characters that follow must be letters, numbers, or underscores (_).
... So I tried to change the password that was 32 characters long to 30 characters and it works.
The tsql accept long password but perl dbi sybase accept ony 30 characters.
Command to connect to default instance on port 1433:
perl -e 'use DBI;DBI->connect("dbi:Sybase:server=10.0.0.1","sa","max_30_characters_longpassword");'
Command to connect to named instance (use port udp 1434 to discover the port):
perl -e 'use DBI;DBI->connect("dbi:Sybase:server=10.0.0.1\\SQL2014","sa","max_30_characters_longpassword");'
Command to connect to named instance when you know the port that sqlserver is listening:
perl -e 'use DBI;DBI->connect("dbi:Sybase:server=10.0.0.1:60036","sa","max_30characters_long_password");'
I used the tcpdump to monitoring the connection to the sqlserver:
tcpdump -qn dst host 10.0.0.1 &
Maybe it helps someone. Thanks

How to connect from ruby to MS Sql Server

I'm trying to connect to the sql server 2005 database from *NIX machine:
I have the following configuration: Linux 64bit
ruby -v
ruby 1.8.6 (2007-09-24 patchlevel 111) [x86_64-linux]
important gems:
dbd-odbc (0.2.4)
dbi (0.4.1)
active record sql server adapter - as plugin
ruby-odbc 0.9996 (installed without any options.)
unixODBC is installed
freeTDS is installed
cat /etc/odbcinst.ini
[FreeTDS]
Description = TDS driver (Sybase/MS SQL)
Driver = /usr/lib/libtdsodbc.so
Setup = /usr/lib/odbc/libtdsS.so
CPTimeout =
CPReuse =
FileUsage = 1
DSN:
DRIVER=FreeTDS;TDS_Version=8.0;SERVER=XXXX;DATABASE=XXX;Port=1433;uid=XXX;pwd=XXXX;"
or
DRIVER=/usr/lib/libtdsodbc.so;TDS_Version=8.0;SERVER=XXXX;DATABASE=XXX;Port=1433;uid=XXX;pwd=XXXX;"
I receive the following error:
>>ActiveRecord::Base.sqlserver_connection({"mode"=>"ODBC", "adapter"=>"sqlserver", "dsn"=>my_dns)
DBI::DatabaseError: IM002 (0) [unixODBC][Driver Manager]Data source name not found, and no default driver specified
from /usr/lib/ruby/1.8/DBD/ODBC/ODBC.rb:95:in `connect'
from /usr/lib/ruby/1.8/dbi.rb:424:in `connect'
from /usr/lib/ruby/1.8/dbi.rb:215:in `connect'
from /opt/ublip/rails/current/vendor/plugins/activerecord-sqlserver-adapter/lib/active_record/connection_adapters/sqlserver_adapter.rb:47:in `sqlserver_connection'
It looks like ODBC unable to find appropriate ODBC driver, but I have no ideas why.
I had a problem with /usr/lib/libtdsodbc.so which is empty in default debian package free-tds dev, but i solved it with remove broken package and installation from sources.
Will appreciate any thought!
Note:
I'm albe to connect using the same steps on mac 10.5
This looks close, and I've gotten the same type of setup to work on Ubuntu 8.04 (with Ruby 1.8.6.) Since this is on Debian, it should be the similar.
These packages should be installed: unixodbc unixodbc-dev freetds-dev libdbd-odbc-ruby tdsodbc
/etc/odbcinst.ini should have something like this:
[FreeTDS]
Description = FreeTDS unixODBC Driver
Driver = /usr/lib/odbc/libtdsodbc.so
Setup = /usr/lib/odbc/libtdsodbc.so
UsageCount = 1
And /etc/freetds/freetds.conf: (where XXX is the database name and NNN... is the IP of the server):
[XXX]
host = NNN.NNN.NNN.NNN
tds version = 8.0
client charset = UTF-8
text size = 262144
port = 1433
Then to connect:
ActiveRecord::Base.sqlserver_connection({"mode"=>"ODBC",
"adapter"=>"sqlserver",
"dsn"=>"DRIVER=FreeTDS;SERVERNAME=XXX;DATABASE=XXX;uid=XXX;pwd=XXX"
)

Resources