Connecting to MonetDB using ODBC - unixodbc

I have tried using unixODBC (version 2.3.2) and the MonetDB ODBC client (version 11.21.5) on both Mac OS X 10.9 and Debian 8, but cannot connect through ODBC using isql on client machines to a MonetDB server running on Debian 8, although it works fine from the server machine.
When issuing isql -v voc on the client machines I get the following error message:
[08001][unixODBC][MonetDB][ODBC Driver 11.21.5]Client unable to establish connection
[ISQL]ERROR: Could not SQLConnect
Here is my .odbc.ini file:
[voc]
Driver = MonetDB
Description = MonetDB voc test database
Servername = <<left out>>
Port = 50000
UserName = monetdb
Password = monetdb
Database = voc
and my /opt/local/etc/odbcinst.ini file:
[MonetDB]
Description = ODBC Driver for MonetDB SQL Server
Driver = /usr/local/monetdb/lib/libMonetODBC.so
Setup = /usr/local/monetdb/lib/libMonetODBCs.so
FileUsage = 1
Interestingly enough I am able to connect using mclient from client machines and the server machine as well using the following command line:
mclient -d voc -u monetdb -h <<left out>>
The server is configured as follows:
monetdbd get all testing/testDBfarm/
property value
hostname <<left out>>
dbfarm testing/testDBfarm/
status monetdbd[37007] 1.7 (Jul2015) is serving this dbfarm
mserver /usr/bin/mserver5
logfile testing/testDBfarm//merovingian.log
pidfile testing/testDBfarm//merovingian.pid
sockdir /tmp
port 50000
exittimeout 60
forward proxy
discovery true
discoveryttl 600
control no
passphrase <unknown>
mapisock /tmp/.s.monetdb.50000
controlsock /tmp/.s.merovingian.50000
Is there anything I am missing here which is needed to let clients connect to a MonetDB server through ODBC?

The debug log of isql (running ODBCDEBUG=/tmp/odbclog isql test) revealed the problem:
The MonetDB ODBC driver has ignored the Servername parameter in my config file.
.odbc.ini:
Servername = LEFT OUT
Log:
SQLConnect: DSN=voc UID=monetdb PWD=monetdb host=localhost port=50000 database=voc.
It is quite unfortunate, that most ODBC drivers use a different name for specifying the server's hostname or IP-address: Servername, Host, or even Server (See: http://www.unixodbc.org/odbcinst.html)
Thus, for MonetDB's ODBC driver we need to use Host to specify the hostname, instead of Servername or Server, as for Postgres or MySQL, e.g.

Related

Error 20009 (severity 9): Unable to connect: Adaptive Server is unavailable or does not exist OS error 111, "Connection refused"

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.

Unable to connect SQL Server with ODBC drivers on linux

I have install the driver odbc 2.3.0 on linux by this reference: https://www.microsoft.com/en-ca/download/confirmation.aspx?id=28160
All these steps work correctly.
This is my configation:
SERVER:
Oracle server is on linux
SQL Server is on windows
SQL Server:
My login and password are the same. It's: demo
When I use cmd and I use the command: "ipconfig", I can get my IP
My IP is: 192.168.0.106
This is how I do my connection manually and it work:
After the installation, i have configure my files odbinst.ini and odbc.ini
This is my file odbcinst.ini:
This is my file odbc.ini:
This is where my driver is download:
My instance name is MSSQLSERVER and TCP-IP and listen all are enable:
Dynamic port is blank and static port is 1433:
As you see, I can be connect on localhost with the command line:
sqlcmd -S 192.168.0.106 -d demo -U demo -P demo
But, I can't connect with my Oracle server on putty with this command line:
isql MSSQLSERVER -v
Why it don't work?
The server is start
Allows remotely connexion is enable
I have add port 1433 in firewall setting
I tried to disable the firewall, nothing change
Something is wrong in my configuration?
Problem reseolve :
Change sqlServer Localhost to SqlServer.
You can't connect 2 server if they are on localhost. You need an oracle SQL Server and SQlServer working not on LocalHost

How to pass instance in freetds - Ubuntu

I am trying to connect to mssql server (2008 R2) from my ubuntu. I have installed freetds driver.
Below is my configuration in freetds.conf:
[titan]
host = SQL_IP_ADDRESS
tds version = 7.0
instance = CENTERFORALLIED\MSSQLSERVER_2K8
Where CENTERFORALLIED\MSSQLSERVER_2K8 is the instance name.
When I try to connect using below command:
tsql -S titan\MSSQLSERVER_2K8 -U user -P pass
OR
tsql -S titan -U user -P pass
OR
tsql -S SQL_IP_ADDRESS -U user -P pass
its not working. I am getting below error:
locale is "en_IN"
locale charset is "UTF-8"
using default charset "UTF-8"
Msg 18456 (severity 14, state 1) from CENTERFORALLIED\SQLEXPRESS Line 1:
"Login failed for user 'ibuser'."
Error 20002 (severity 9):
Adaptive Server connection failed
There was a problem connecting to the server
I am not sure why this is trying to connect to SQLEXPRESS instance. My instance is MSSQLSERVER_2K8 and I am explicitly mentioned it in config file and even tried in arguments.
instance is MSSQLSERVER_2K8 (w/o the hostname part). You can alternatively conf directly the port.
Note that resolving the instance to a port relies on the SQL Server Browser Service being enabled and started. If is not started then you must use the port explicitly, and the port must be statically configured (not dynamic).

How to connect ms sql database using perl in Windows?

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

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