1
votes

Trying to use sqlcmd from mssql-tools package (loosly following the docs here: https://github.com/mkleehammer/pyodbc/wiki/Connecting-to-SQL-Server-from-RHEL-6-or-Centos-7) and seeing error

Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : Data source name not found and no default driver specified.

even though I believe that both DSN and driver are specified (see below)

[airflow@airflowetl ~]$
[airflow@airflowetl ~]$
[airflow@airflowetl ~]$ # trying to connect to DB via DSN (-S option)
[airflow@airflowetl ~]$ /opt/mssql-tools/bin/sqlcmd -Q "select count(*) from MYTABLE" -D -S "MyMSSQLServer" -U "myuser" -P "mypass" -d mydb -W -h-1 -k
Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : Data source name not found and no default driver specified.
[airflow@airflowetl ~]$
[airflow@airflowetl ~]$
[airflow@airflowetl ~]$ # checking odbc config files
[airflow@airflowetl ~]# odbcinst -j
unixODBC 2.3.7
DRIVERS............: /etc/odbcinst.ini
SYSTEM DATA SOURCES: /etc/odbc.ini
FILE DATA SOURCES..: /etc/ODBCDataSources
USER DATA SOURCES..: /root/.odbc.ini
SQLULEN Size.......: 8
SQLLEN Size........: 8
SQLSETPOSIROW Size.: 8
[airflow@airflowetl ~]$ cat /etc/odbc.ini 
[MyMSSQLServer]
Driver=ODBC Driver 17 for SQL Server
Description=My MS SQL Server
Trace=No
Server=172.18.1.23

[airflow@airflowetl ~]$ cat /etc/odbcinst.ini 

[airflow@airflowetl ~]$ ls -lha /opt/microsoft/msodbcsql17/lib64/libmsodbcsql-17.4.so.2.1 
-rwxr-xr-x 1 root root 2.0M Sep 26 06:19 /opt/microsoft/msodbcsql17/lib64/libmsodbcsql-17.4.so.2.1

Notice that /etc/odbcinst.ini is blank when (I think) it should corespond to Driver entries in the odbc.ini file. Should I just fill this in manually? Why does it not auto-fill in this case (as it has done on other machines where I have set up odbc)?

Not much experience with ODBC setup, so not sure what to make of this error. Anyone with more experience have any fuirther debugging tips or know how to fix?

1
Manually filled in /etc/odbcinst.ini based on the odbc* files on a previous machine where had set this up seems to have fixed the problem. Still not sure why the odbcinst.ini file was not autofilling though. See serverfault.com/a/622088/456930. - lampShadesDrifter

1 Answers

0
votes