为连接字符串属性指定的无效值

问题描述 投票:0回答:1
import pyodbc as po    

connection_string = """
driver=ODBC Driver 17 for SQL Server;
server=SHADOW-LN4F5NUO;
database=FBI_Crime_Data;
trusted_connection=True;
"""

connection = po.connect(connection_string)

输出:

Traceback (most recent call last):
  File "C:\Program Files\JetBrains\PyCharm 2019.3.1\plugins\python\helpers\pydev\pydevd.py", line 1434, in _exec
    pydev_imports.execfile(file, globals, locals)  # execute the script
  File "C:\Program Files\JetBrains\PyCharm 2019.3.1\plugins\python\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "C:\Users\Jack\Desktop\GitHub\FBI_Crime_Data_Analysis\main.py", line 133, in <module>
    import_file(file_location="data/ASR122016.TXT")
  File "C:\Users\Jack\Desktop\GitHub\FBI_Crime_Data_Analysis\main.py", line 122, in import_file
    export_dataframe_to_SQL_Server(df=df, table_name=table_name)
  File "C:\Users\Jack\Desktop\GitHub\FBI_Crime_Data_Analysis\main.py", line 40, in export_dataframe_to_SQL_Server
    connection = po.connect(connection_string)
pyodbc.OperationalError: ('08001', "[08001] [Microsoft][ODBC Driver 17 for SQL Server]Invalid value specified for connection string attribute 'trusted_connection' (0) (SQLDriverConnect)")
  • 服务器名称正确。
  • 数据库名称正确
  • ODBC驱动程序存在。
  • SSMS中的Windows身份验证有效。
python sql-server pycharm pyodbc
1个回答
0
投票

根据this microsoft documentation,识别出的值为truefalseyesnosspi

也许它不喜欢大写字母T?尝试使用true而不是True

© www.soinside.com 2019 - 2024. All rights reserved.