0

I'm trying to connect to a MS SQL server from a Linux machine, but can't get ODBC to work.

The following command works and I get a shell:

sqlcmd -S tcp:<servername>,<dynamic port> -U <SQL username> -P <SQL user password>

I have the following in my ODBC.ini file

[example]
Driver = ODBC Driver 17 for SQL Server 
Server = <servername>
Port = <dynamic port>
User = <SQL username>
Password = <SQL user password>

As of my understanding this command should give the same results as the one earlier:

sqlcmd -D -S example

But I get the following error

Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : Login timeout expired.
Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : TCP Provider: Error code 0x2749.
Sqlcmd: Error: Microsoft ODBC Driver 17 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..

Additional info:

[user@server ~]$ odbcinst -j
unixODBC 2.3.7
DRIVERS............: /etc/odbcinst.ini
SYSTEM DATA SOURCES: /etc/odbc.ini
FILE DATA SOURCES..: /etc/ODBCDataSources
USER DATA SOURCES..: /home/ictadmin/.odbc.ini
SQLULEN Size.......: 8
SQLLEN Size........: 8
SQLSETPOSIROW Size.: 8

[user@server ~]$ cat /etc/odbcinst.ini
[ODBC Driver 17 for SQL Server]
Description=Microsoft ODBC Driver 17 for SQL Server
Driver=/opt/microsoft/msodbcsql17/lib64/libmsodbcsql-17.10.so.1.1
UsageCount=1
MeMario
  • 25
  • 6

2 Answers2

1

Port is not a valid keyword in odbc.ini on Linux for Microsoft's Linux ODBC driver.

You need to specify Server = <hostname>,<port> in ODBC.ini. If you're using a dynamic port, leave the port off.

Rob Shinn
  • 79
  • 1
0

I got it working by disabling SELinux

setenforce 0

and using the following ODBC.ini

[example]
Driver = ODBC Driver 17 for SQL Server 
Server = tcp:<servername>,<port>

This was on AlmaLinuxOS 9 (5.14.0-70.17.1.el9_0.x86_64)

MeMario
  • 25
  • 6