pyodbc.drivers()返回驱动程序列表,但我的python脚本不在列出的任何ODBC驱动程序运行

发布于 2025-02-09 11:33:37 字数 708 浏览 1 评论 0 原文

ran print(pyodbc.drivers()),它打印了可用驱动程序的列表...在Docker中运行一个SQL容器,我试图从Python脚本操纵

connector = pyodbc.connect('Driver={ODBC Driver 18 for SQL Server};' 'Server=cbbcb967dacb;' 'Database=testdb;' 'UID=sa;' 'PWD=Working@2022' 'Trusted_Connection=yes;')
connector.execute()

cursor = connector.cursor()
cursor.execute('SELECT * FROM inventory')

for i in cursor:
    print(i)

数据库:

pyodbc.operationalError :('08001','[08001] [Microsoft] [SQL Server的ODBC驱动程序18]名为Pipes Provider:无法打开与SQL Server [53]的连接。(53)(53)(SQLDRiverConnect); [08001] [Microsoft] [SQL Server的ODBC驱动程序18]登录超时到期(0); SQL Server未能找到实例名称,如果SQL Server配置为远程连接

Ran print(pyodbc.drivers()) and it printed the list of available drivers... running a SQL container in docker I'm trying to manipulate the database from a python script

connector = pyodbc.connect('Driver={ODBC Driver 18 for SQL Server};' 'Server=cbbcb967dacb;' 'Database=testdb;' 'UID=sa;' 'PWD=Working@2022' 'Trusted_Connection=yes;')
connector.execute()

cursor = connector.cursor()
cursor.execute('SELECT * FROM inventory')

for i in cursor:
    print(i)

The error I get is:

pyodbc.OperationalError: ('08001', '[08001] [Microsoft][ODBC Driver 18 for SQL Server]Named Pipes Provider: Could not open a connection to SQL Server [53]. (53) (SQLDriverConnect); [08001] [Microsoft][ODBC Driver 18 for SQL Server]Login timeout expired (0); [08001] [Microsoft][ODBC Driver 18 for SQL Server]A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online. (53)')

But the ODBC Driver is installed

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

相思故 2025-02-16 11:33:37

例外情况建议是网络错误, cbbcb967dacb 看起来像容器的主机名,您可能需要直接尝试其IP地址,或者如果您按照docker在docker中运行SQL Server,则根据文档

您是否可以 telnet CBBCB967DACB 1433

根据评论中的讨论,如果您的Docker容器正在运行并根据MSSQL教程启动,则以下连接字符串应起作用:

"DRIVER={ODBC Driver 18 for SQL Server};SERVER=localhost;UID=SA;PWD={Working@2022};DATABASE=testdb;"

The exception suggests a network error, cbbcb967dacb looks like the hostname of the container, you might want to try its IP address directly or localhost if you ran SQL Server in docker as per the documentation.

Are you able to telnet cbbcb967dacb 1433 ?

Based on the discussion in the comments, if your docker container is running and was started as per the MSSQL tutorial, the following connection string should work:

"DRIVER={ODBC Driver 18 for SQL Server};SERVER=localhost;UID=SA;PWD={Working@2022};DATABASE=testdb;"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文