python - 登录失败(pyodbc.InterfaceError)('28000', "[28000] [Microsoft][ODBC SQL Server Driver][SQL Server]Login failed for user ' xxxx'

标签 python azure connection

我在使用 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驱动是否安装成功。

enter image description here

隐私

下面的代码对我有用。

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()

enter image description here

关于python - 登录失败(pyodbc.InterfaceError)('28000', "[28000] [Microsoft][ODBC SQL Server Driver][SQL Server]Login failed for user ' xxxx',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65134915/

相关文章:

powershell - 列出属于特定子网的所有 azure vm

azure - 如何在 azure 上打开 websocket 端口?

java - Eclipse JAVA程序中找不到Oracle数据库驱动程序

javascript - 如何将使用 javascript 和 ASP.NET 生成的字段中的数据发送到 Microsoft SQL?

Python 抑制 shell 输出

Python 语义 - for 循环声明中的多个参数

python - 实现常微分方程组的循环

python - 在 pandas 中使用 bool 过滤器标量广播 groupby

asp.net - 无法加载文件或程序集 'Microsoft.TeamFoundation.WorkItemTracking.Client.Cache' 或其依赖项之一

docker - kubernetes中工作节点上的连接拒绝错误