Connect SQL Server database with Python

2

I have this code that I started, to be able to connect to my server of SQL Server by means of Python in Ubuntu , all the components of: server, user, password, base already make sure they are correct.

But when I run the file name bot.py I get the following error:

I have not been able to correct it, I do not know what I am doing wrong: (.

Thank you in advance for the help.

    
asked by Santiago Huh 26.07.2017 в 00:16
source

1 answer

3

The error in this case was due to two factors:

  • Lack of necessary dependencies, especially from the freetds-dev package, implementation of the TDS protocol ( Tabular Data Stream) and which is the one that allows the native communication with SQL-Server.

    The procedure for the correct installation of pymssql to make it work with SQL Server in Ubuntu is as follows:

    • Installation of the dependencies:

        

      $ sudo apt-get update
        $ sudo apt-get --assume-yes install freetds-dev freetds-bin
        $ sudo apt-get --assume-yes install python-dev python-pip

    • Install pymssql (in the system or virtual environment as preferred):

        

      $ pip install pymssql

    For more information see Microsoft documentation about it.

  • It is recommended to pass the connection parameters by name and not by position. If we pass the parameters by position and skip any one to keep the default value (such as the port) we will have errors as is logical:

    server = "xx.xxx.x.xxx"
    user = "usuario"
    password = "1234"
    base = "Mi_base_de_datos"
    
    conexion_sql = pymysql.connect(host=server, user=user, passwd=password, db=base)
    
answered by 26.07.2017 / 03:03
source