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
Related
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
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 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 want to connect ms sql database through perl language. The following steps are I made.
I've created a database table in the name "SampleDb"
Configured ODBC and I've set name for sql server driver as "SampleDb"
Now I've tried to connect as follows,
,
my $dbs = "dbi:ODBC:DRIVER={SQL Server};SERVER={SampleDb}";
my $dbh = DBI->connect($dbs, "username", "password");
But Now I got the following error
DBI connect('DRIVER={SQL Server};SERVER={SampleDB}','username',...) failed: [Microsoft][ODBC SQL Server Driver][DBNETLIB]SQL Server does not exist or access denied. (SQL-08001) [state was 08001 now 01000]
[Microsoft][ODBC SQL Server Driver][DBNETLIB]ConnectionOpen (Connect()). (SQL-01000)
How to solve this ? or
How to Connect ms sql using perl through ODBC ?
This question has already been answered (and accepted !!). Just providing detailed steps for connecting MSSQL server from perl running on Linux using ODBC.
Before you get into perl stuff, you need to install and configure odbc environment on the Linux box.
Install below packages:
Fedora:
unixODBC-devel.i686
unixODBC.i686
AND
freetds.i686
freetds-devel.i686
freetds-doc.i686
Ubuntu:
unixodbc
unixodbc-dev
AND
freetds-bin
freetds-common
freetds-dev
tdsodbc
After these packages are installed we MUST be able to use freetds to test authentication network authentication with the MS SQL server.
root#ubuntu:/home# tsql -S <db_host_name> -p 1433 -U perluser -P password
locale is "en_IN"
locale charset is "UTF-8"
1>
If above fails, then check the MSSQL db permission for this user. Also check MSSQL logs. Do not proceed until you run above command successfully. Also, failure of above command has nothing to do with the unixodbc OR freetds configuration.
Configure the odbc.ini and odbcinst.ini and freetds.conf files.
/etc/odbc.ini will contain the DSN information:
root#ubuntu:/home# cat /etc/odbc.ini
[odbc-test]
Description = test
Driver = ms-sql
Servername = ms-sql
Database = <db_name>
UID = perluser
Port = 1433
Please note that, the Driver field refers to /etc/odbcinst.ini context named [ms-sql].
The Servername field refers to the /etc/freetds.conf context that I also named [ms-sql].
Database field is optional but I am using it as I want to connect to a particular Database.
/etc/odbcinst.ini file contains the Driver information:
root#ubuntu:/home# cat /etc/odbcinst.ini
[ms-sql]
Description = TDS Conection
Driver = /usr/lib/odbc/libtdsodbc.so
Setup = /usr/lib/odbc/libtdsS.so
UsageCount = 1
FileUsage = 1
The odbcinst.ini file simply directs the odbc.ini file to the appropriate driver.
The Driver and Setup entries for Fedora is /usr/lib/libtdsodbc.so and /usr/lib/libtdsS.so respectively.
Also, for 64-bit Linux box, it would be Driver64 and Setup64 instead of Driver and Setup respectively.
Configure /etc/freetds/freetds.conf ( /etc/freetds.conf for Fedora). It contains TDS information. Here is mine:
root#ubuntu:/home# tail /etc/freetds/freetds.conf
[ms-sql]
host = <db_host_name>
port = 1433
tds version = 7.0
dump file = /var/log/freetds.log
Please note that, above context name [ms-sql] is the value of Servername in odbc.ini.
Test the configuration by connecting the MSSQL server using isql command:
root#ubuntu:/home# isql -v odbc-test perluser password
+---------------------------------------+
| Connected! |
| |
| sql-statement |
| help [tablename] |
| quit |
| |
+---------------------------------------+
SQL>
The odbc-test portion of the isql command was defined in the odbc.ini file.
You HAVE to receive above output which says Connected!. If you don’t, then there is some problem in your configuration and go through all the above steps again.
Now,
Install Perl DBI module.
Install DBD::ODBC module .
Then use the ODBC in your perl code as below:
my $dbh = DBI->connect ('dbi:ODBC:odbc-test', 'perluser', 'password');
Hope This Helps.
This is for connecting MSSQL using perl in Windows.
Instead of ODBC, try OLEDB. The following code will help you.
my $host = 'sample\sql';
my $database = 'SampleDB';
my $user = 'sa';
my $auth = 'password';
$dsn = "Provider=sqloledb;Trusted Connection=yes;";
$dsn .= "Server=$host;Database=$database";
my $dbh = DBI->connect("dbi:ADO:$dsn",$user,$auth,{ RaiseError => 1, AutoCommit => 1}) || die "Database connection not made: $DBI::errstr";
Reference How to connect Ms Sql using Perl