gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 16:47:06 24 4
gpt4 key购买 nike

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 身份验证有效。

最佳答案

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

pyodbc documentation说,您可以通过提供 Trusted_Connection 属性使用您的 Windows 帐户而不是用户名/密码进行身份验证:Trusted_Connection=yes

所以它看起来是 connectionstrings sql server main page向您显示 .Net 库的连接字符串。如果您单击“ODBC 驱动程序”下特定版本驱动程序的任何页面(如 171311 ),它会显示 Trusted_Connection=yes

关于python - 为连接字符串属性指定的值无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60143888/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com