-1

i have an issue connecting an mssql database via odbc in ubuntu 16.04 LTS. I have installed unix odbc and mussel driver.

mssql driver is declared in odbcinst.ini :

statadmin@dsc-stat:~$ cat /etc/odbcinst.ini [ODBC Driver 13 for SQL Server] Description=Microsoft ODBC Driver 13 for SQL Server Driver=/opt/microsoft/msodbcsql/lib64/libmsodbcsql-13.0.so.1.0 UsageCount=1

My DSN named DW16 is in odbc.ini :

statadmin@dsc-stat:~$ cat /etc/odbc.ini [DW16] Driver=ODBC Driver 13 for SQL Server Servername=10.0.0.52 Port=1433

a direct connexion(without DSN) on the database works :

statadmin@dsc-stat:~$ sqlcmd -S dsc-bdd1.dscptl.loc -U statsql Password: 1> select top 5 libdef from defaut 2> ; 3> GO

libdef

DEFAUT PONCTUEL SUREPAISSEUR PLIS CASSES TISSAGE FIL TIRANT FIL (5 rows affected)

But using the DSN, I get an error :

statadmin@dsc-stat:~$ sqlcmd -D -S DW16 -U statsql Password: Sqlcmd: Error: Microsoft ODBC Driver 13 for SQL Server : Login timeout expired. Sqlcmd: Error: Microsoft ODBC Driver 13 for SQL Server : TCP Provider: Error code 0x2AFA. Sqlcmd: Error: Microsoft ODBC Driver 13 for SQL Server : A network-related or instance-specific error has occurred while establishing a connection to SQL Server . Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online..

I suppose firewall, tcp porter authentification issues aren't here as direct connexion works. I've tried with IP address as well as with server name with no difference.

hope someone here will have a good idea to help me.

Thomas

  • In your direct connection you use server name dsc-bdd1.dscptl.loc and on the DSN you have it defined as ip 10.0.0.52, are you sure both resolve to the same appropiate host? – bistoco Mar 12 '17 at 18:54
  • Yes, i actually tested with both ip and name. – Thomas Mar 13 '17 at 20:46
0

Finally got the answer, I don't know where my colleague found the answer, but here what he send me:

[MSSQLTest] Driver = ODBC Driver 11 for SQL Server Server = [protocol:]server[,port]

Note:

Port is not a valid keyword in the ~/.odbc.ini file

for the Microsoft ODBC driver on Linux

You can optionally specify the protocol and port to connect to the server.

For example, Server = tcp:servername,12345.

To connect to a named instance on a static port, use Server = servername,port_number. Connecting to a dynamic port is not supported.

my odbc.ini , needs to be:

[DW16] 
Driver=ODBC Driver 13 for SQL Server 
Server=TCP:dsc-bdd1.dscptl.loc,1433

It works also with IP address. Hope it can help someone else.

Thomas

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.