Connect docker python to SQL server with pyodbc

后端 未结 7 1969
迷失自我
迷失自我 2020-11-28 08:50

I\'m trying to connect a pyodbc python script running in a docker container to login to a MSSQL database I have tried all sorts of docker files, but not been able to make th

相关标签:
7条回答
  • 2020-11-28 09:34

    Need to Run:

    sudo apt-get install gcc
    

    need to add a odbcinst.ini file containing:

    [FreeTDS]Description=FreeTDS Driver Driver=/usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so Setup=/usr/lib/x86_64-linux-gnu/odbc/libtdsS.so
    

    need to add folowing to docker file

    ADD odbcinst.ini /etc/odbcinst.ini
    RUN apt-get update
    RUN apt-get install -y tdsodbc unixodbc-dev
    RUN apt install unixodbc-bin -y
    RUN apt-get clean -y
    

    need to change connection in .py to

    connection = pyodbc.connect('Driver={FreeTDS};'
                                'Server=xxxxx;'
                                'Database=DCMM;'
                                'UID=xxxxx;'
                                'PWD=xxxxx')
    

    Now the container compiles, and gets data from SQL server

    0 讨论(0)
提交回复
热议问题