Error when trying to create new database table in SQL Server 2016 from csv file while using python 3.5 with pandas and sqlalchemy

前端 未结 1 1394
不知归路
不知归路 2020-12-06 08:50

Problem

I am trying to use python to read my csv file and put it into Microsoft SQL Server 2016 as a new table. Simply put, I don\'t want to create a table on SQL

相关标签:
1条回答
  • 2020-12-06 09:16

    You should explicitly specify the MS SQL Server driver if you use SQLAlchemy version 1.0.0+:

    Example:

    engine = create_engine("mssql+pyodbc://scott:tiger@myhost:port/databasename?driver=SQL+Server+Native+Client+10.0")
    

    Changed in version 1.0.0: Hostname-based PyODBC connections now require the SQL Server driver name specified explicitly. SQLAlchemy cannot choose an optimal default here as it varies based on platform and installed drivers.

    List of Native SQL Server Client Names

    • SQL Server 2005:

    SQL Server Native Client

    • SQL Server 2008:

    SQL Server Native Client 10.0

    • SQL Server 2016:

    SQL Server Native Client 11.0


    Alternatively you can use pymssql:

    engine = create_engine('mssql+pymssql://<username>:<password>@<freetds_name>/?charset=utf8')
    
    0 讨论(0)
提交回复
热议问题