8

I know this question was asked before but I never really got a proper answer that would solve my problem. I am trying to connect to a SQL server on a windows machine from a linux Open Suse12.4 machine.

pyodbc.connect('DRIVER={SQL Server};SERVER=servername;DATABASE=dbname;UID=userid;PWD=password')

the exact error I got was as below:

pyodbc.Error: ('01000', "[01000] [unixODBC][Driver Manager]Can't open lib 'SQL Server' : file not found (0) (SQLDriverConnect)")

and below is my odbcinst.ini file :

[Easysoft ODBC-SQL Server]
Driver=/usr/local/easysoft/sqlserver/lib/libessqlsrv.so
Setup=/usr/local/easysoft/sqlserver/lib/libessqlsrvS.so
Threading=0
FileUsage=1
DontDLClose=1
UsageCount=2

[Easysoft ODBC-SQL Server SSL]
Driver=/usr/local/easysoft/sqlserver/lib/libessqlsrv_ssl.so
Setup=/usr/local/easysoft/sqlserver/lib/libessqlsrvS.so
Threading=0
FileUsage=1
DontDLClose=1
UsageCount=2
halfer
  • 19,824
  • 17
  • 99
  • 186
BarathanR
  • 151
  • 1
  • 2
  • 8
  • 3
    See if [this answer](http://stackoverflow.com/questions/16280304/pyodbc-data-source-name-not-found-and-no-default-driver-specified/16280935#16280935) helps. – Benny Hill Nov 26 '16 at 06:01
  • thank you so much Benny! the link you sent certainly helped! the issue was my odbc.ini and odbcinst.ini files were in /etc/. however, running odbcinst -j shows that those 2 files suppose to be at /etc/unixODBC/. so i just copied over the file and it solved my problem! thank you again – BarathanR Nov 28 '16 at 05:12
  • @BarathanR is this issue resolved then? – meet-bhagdev Nov 28 '16 at 21:11
  • Possible duplicate of [Pyodbc - "Data source name not found, and no default driver specified"](https://stackoverflow.com/questions/16280304/pyodbc-data-source-name-not-found-and-no-default-driver-specified) – kenorb Oct 24 '17 at 12:20
  • Are you absolute sure your driver packages have been installed? I had similar error messages when python could not connect to OBDC driver. – vahvero Jan 04 '20 at 01:26

3 Answers3

1

This post helped me to pinpoint my issue. My situation is that i have install the ODBC driver following this post "https://github.com/mkleehammer/pyodbc/wiki/Connecting-to-SQL-Server-from-RHEL-6-or-Centos-7" and turn out, i found that DRIVER "SQL Server" does not exist in my ini file. I changed DRIVER in connection string as "cnxn = pyodbc.connect("Driver={ODBC Driver 13 for SQL Server};Server=XXXXX;Database=XXX;Uid=XXX;Pwd=XXX;")" and it works

Benny Chan
  • 333
  • 1
  • 4
  • 10
1

If you are using an offline REHL server, then follow the below method to setup connection to Microsoft SQL Server.

  1. Download UNIXODBC & MSSQLTools packages—e.g., unixODBC-2.3.7-1.rh.x86_64.rpm/mssql-tools-17.9.1.1-1.x86_64.rpm—from the Microsoft repo, as per your REHL version

  2. Place downloaded files on the REHL server via winscp or any ssh client

  3. Install these two files in sequence given below:

    • yum localinstall unixODBC-2.3.7-1.rh.x86_64.rpm
      
    • yum localinstall mssql-tools-17.9.1.1-1.x86_64.rpm)
      
  4. Go to the installation folder and copy the path as shown in e.g.,

    /opt/microsoft/msodbcsql17/lib64/libmsodbcsql-17.9.so.1.1
    
  5. Put this path in code:

    driverpath = r"/opt/microsoft/msodbcsql17/lib64/libmsodbcsql-17.9.so.1.1"
    

Your problem will get solved.

Jeremy Caney
  • 7,102
  • 69
  • 48
  • 77
0

Pyodbc is not able to locate Driver = {SQL Server} used. In my case, It was mainly because the name I gave in odbcinst.ini file and related files wasn't correct.

Instead using Driver =/usr/local/lib/libmsodbcsql.13.dylib; using in connection uri helped me connect and hence understand that my configuration files were incorrect.

  • Different types of libraries for connecting to SQL Server installed which causes the conflict.

I corrected it and was able to connect.

Amogh Antarkar
  • 129
  • 2
  • 16