我在使用 python 3.8 连接到 sql 服务器时遇到了很大的问题。我想知道我是否需要降级到 3.7 python,是否还有其他地方做错了?
这是我的代码和错误消息:
params = urllib.parse.quote_plus \
('Driver={SQL
Server};Server=tcp:xxxxx.database.windows.net,1433;
Database=GroceryDB;Uid=xxxxx;Pwd=
{xxxx};Encrypt=no;Connection Timeout=30;')
conn_str = 'mssql+pyodbc:///?odbc_connect={}'.format(params)
engine =
sqlalchemy.engine.create_engine(conn_str,echo=False,pool_pre_
ping=True)
登录失败 (pyodbc.InterfaceError) ('28000', "[28000] [Microsoft][ODBC SQL Server 驱动程序][SQL Server]用户 'xxxx' 登录失败。
最佳答案
最新
您可以按照文档(Open the ODBC Data Source Administrator)检查odbc驱动是否安装成功。
隐私
下面的代码对我有用。
from urllib import parse
import pyodbc
from sqlalchemy import create_engine
import urllib
params = parse.quote_plus \
(r'Driver={ODBC Driver 17 for SQL Server};Server=tcp:yoursqlserver.database.windows.net,1433;Database=dbname;Uid=sasasa;Pwd={pwd};Encrypt=yes;TrustServerCertificate=no;Connection Timeout=30;')
conn_str="mssql+pyodbc:///?odbc_connect={}".format(params)
engine= create_engine (conn_str,echo=True)
connection = engine.connect()
result = connection.execute("select 1+1 as res")
for row in result:
print("res:", row['res'])
connection.close()
关于python - 登录失败(pyodbc.InterfaceError)('28000', "[28000] [Microsoft][ODBC SQL Server Driver][SQL Server]Login failed for user ' xxxx',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65134915/