[odb-users] Cannot connect to Microsoft SQL server in Ubuntu 18.04

ravil.nugmanov at gmail.com ravil.nugmanov at gmail.com
Thu May 28 23:51:47 EDT 2020


Hi, 

 

Previously by mistake sent e-mail from different address, which is not
subscribed to the mail list, sorry.

 

First of all, thank you for this great library!

Meanwhile, the issue described below was solved using older version of
unixOdbc (2.3.1) and MS SQL native client library, following instructions at
https://www.codesynthesis.com/~boris/blog/2011/12/02/microsoft-sql-server-od
bc-driver-linux/

The original issue was:

 

I am using odb version 2.5.0 in Ubuntu 18.04, trying to connect to MS SQL
Server, but getting "invalid handle" error.

ODBC driver from Microsoft is installed following steps described in
https://docs.microsoft.com/en-us/sql/connect/odbc/linux-mac/installing-the-m
icrosoft-odbc-driver-for-sql-server?view=sql-server-ver15#ubuntu17

Note that with sqlcmd command I can connect to the database successfully.

In C++ code using contractor for odb::mssql::database which takes
connection string as argument: 

Server=tcp:192.168.1.80,1433;Driver=ODBC Driver 17 for SQL Server;Connection
Timeout=10;Uid=sa;Pwd=password;Encrypt=no;Database=master;


I wonder, what can cause this connection problem? Should I do something with
files /etc/odbc.ini or /etc/obdcinst.ini ? Or maybe option Driver is not
correct? There is the entry with drive name in file /etc/odbcinst.ini
though:

[ODBC Driver 17 for SQL Server]

Description=Microsoft ODBC Driver 17 for SQL Server

Driver=/opt/microsoft/msodbcsql17/lib64/libmsodbcsql-17.5.so.2.1

UsageCount=1

 

Tried to pass connection string with Driver= set to so file name too, no
luck:

[Server=tcp:192.168.1.80,1433;Driver=/opt/microsoft/msodbcsql17/lib64/libmso
dbcsql-17.5.so.2.1;UID=sa;PWD=password;Connection
Timeout=10;Encrypt=no;Database=master;

 

The same code works in Windows build.

 

Thank you, Ravil



More information about the odb-users mailing list