connect to mssql with python/linux

done for a friend :

  1. install rpm’s
    sudo yum install -y freetds unixODBC unixODBC-devel freetds-libs python3-pyodbc
  2. create odbc.ini and odbcinst.ini
    1. for sybase go thereĀ Unix ODBC Sybase
    2. for oracle go thereĀ Unix ODBC Oracle
    3. for mssql
      1. ~/.odbc.ini : the Database definition
        [DB01]
        Driver = FreeTDS
        Description = DB01
        Server = src01
        Port = 1433
        Database = DB01
      2. ~/.odbcinst.ini : the driver definition
        [FreeTDS]
        Description = Free Sybase & MS SQL Driver
        Driver64 = /usr/lib64/libtdsodbc.so.0
        Setup64 = /usr/lib64/libtdsS.so.2
        Port = 1433
  3. test with isql
    isql -v DB01 myuser mypw
  4. test with python3
    import pyodbc
    
    conn = pyodbc.connect('DSN=DB01;UID=myuser;PWD=mypw')
    
    cursor = conn.cursor()
    
    cursor.execute('select \'hello world\'')
    
    print (cursor.fetchone()[0])
    hello world

HTH