-1

Below is the error while connecting to SQL server from linux:

connection = pyodbc.connect(connect_string)
pyodbc.Error: ('01000', u"[01000] [unixODBC][Driver Manager]Can't open lib /usr/local/lib/libmsodbcsql.17.dylib' : file not found (0) (SQLDriverConnect)")
Details in odbcinst -j

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
QFII
  • 71
  • 9
  • 1
    It appears you have a driver missing. Check this out: https://askubuntu.com/questions/651460/cant-connect-to-ms-sql-with-pyodbc – AmourK Oct 13 '19 at 01:45
  • Above link and https://learn.microsoft.com/en-us/sql/connect/odbc/linux-mac/installing-the-microsoft-odbc-driver-for-sql-server?view=sql-server-ver15 should be helpful for you. – san Oct 13 '19 at 01:54
  • I have installed driver: [ODBC Driver 17 for SQL Server] Description=Microsoft ODBC Driver 17 for SQL Server Driver=/usr/local/lib/libmsodbcsql.17.dylib – Rangaragu Nivas Oct 13 '19 at 01:57
  • @RangaraguNivas - Which flavour of Linux are you using? – Gord Thompson Oct 13 '19 at 11:38

1 Answers1

1

Try something like this:

cnxn = pyodbc.connect('DRIVER={/opt/microsoft/msodbcsql17/lib64/libmsodbcsql-17.3.so.1.1};SERVER='+server+';DATABASE='+database+';uid='+username+';pwd='+ password)

Where "{/opt/microsoft/msodbcsql17/lib64/libmsodbcsql-17.3.so.1.1}" is your driver that you need to find in your system.

"/usr/local/lib/libmsodbcsql.17.dylib"

GiovaniSalazar
  • 1,999
  • 2
  • 8
  • 15
  • Segmentation fault (core dumped) getting this error cxnn = pyodbc.connect('DRIVER={/opt/microsoft/msodbcsql/lib64/libmsodbcsql-11.0.so.2270.0};SERVER={localhost};DATABASE={test};uid={user};pwd={1234}') – Rangaragu Nivas Oct 13 '19 at 04:10
  • but your libmsodbcsql-11.0.so.2270.0 is in /opt/microsoft/msodbcsql/lib64/ ??? – GiovaniSalazar Oct 13 '19 at 04:17
  • yes libmsodbcsql-11.0.so.2270.0 is in /opt/microsoft/msodbcsql/lib64/ – Rangaragu Nivas Oct 13 '19 at 04:21
  • check the odbc.ini and odbcinst.ini https://github.com/mkleehammer/pyodbc/wiki/Drivers-and-Driver-Managers – GiovaniSalazar Oct 13 '19 at 04:39
  • cat /etc/odbcinst.ini [ODBC Driver 17 for SQL Server] Description=Microsoft ODBC Driver 17 for SQL Server Driver=/usr/local/lib/libmsodbcsql.17.dylib UsageCount=2 [ODBC Driver 11 for SQL Server] Description=Microsoft ODBC Driver 11 for SQL Server Driver=/opt/microsoft/msodbcsql/lib64/libmsodbcsql-11.0.so.2270.0 Threading=1 UsageCount=1 I have updated as below cat /etc/odbc.ini Decription = ODBC Driver 11 for SQL Server Driver = /opt/microsoft/msodbcsql/lib64/libmsodbcsql-11.0.so.2270.0 – Rangaragu Nivas Oct 13 '19 at 04:52
  • I think maybe you have forgotten some of these steps in the installation: https://learn.microsoft.com/en-us/sql/connect/odbc/linux-mac/installing-the-microsoft-odbc-driver-for-sql-server?view=sql-server-ver15 – GiovaniSalazar Oct 13 '19 at 05:07
  • NAME="CentOS Linux" – Rangaragu Nivas Oct 13 '19 at 13:41
  • I reinstalled drivers and getting below error: pyodbc.OperationalError: ('HYT00', u'[HYT00] [Microsoft][ODBC Driver 13 for SQL Server]Login timeout expired (0) (SQLDriverConnect)') – Rangaragu Nivas Oct 13 '19 at 16:16
  • console : telnet IP_Server_SQL 1433 – GiovaniSalazar Oct 13 '19 at 16:36
  • Telnet is not working on Linux. I did ping SQL_IP and getting a response. no errors – Rangaragu Nivas Oct 13 '19 at 17:27