You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何解决Python通过pyodbc连接SQL Server时出现的08001连接错误

Troubleshooting Your Python-SQL Server Connection Error

First, let's fix the most obvious issue in your connection string—you’ve got a typo! You wrote Trusted_Connected=yes; but the correct attribute name is Trusted_Connection=yes;. That’s exactly why the error mentions "Invalid connection string attribute"—the ODBC driver doesn’t recognize the misspelled key.

Next, let’s tackle the core connectivity problem (the "Named Pipes Provider: Could not open a connection to SQL Server [67]" error):

  • Verify your server/instance name: The value HEPHAISTEONAE5E/FUHRP might not resolve correctly in your VM. Try these alternatives:

    • Use localhost\FUHRP if you’re connecting to an instance running locally on the VM.
    • Swap the machine name for the VM’s IP address (e.g., 192.168.1.100\FUHRP)—name resolution can fail in virtual environments, so using an IP often bypasses that.
    • Double-check the instance name in SQL Server Configuration Manager under "SQL Server Services" (it should show as SQL Server (FUHRP) to confirm the instance is running).
  • Enable required network protocols: Even if remote connections are allowed, the SQL Server instance might not have the right protocols turned on:

    1. Open SQL Server Configuration Manager.
    2. Navigate to SQL Server Network Configuration > Protocols for FUHRP.
    3. Ensure both TCP/IP and Named Pipes are set to "Enabled".
    4. Restart the SQL Server (FUHRP) service for changes to take effect.
  • Check Windows Firewall settings: The VM’s firewall could be blocking the connection to SQL Server:

    • For named instances (like FUHRP), SQL Server uses a dynamic port by default. You can either:
      1. Add an exception for sqlservr.exe (usually in C:\Program Files\Microsoft SQL Server\MSSQL15.FUHRP\MSSQL\Binn).
      2. Set a fixed port for the instance in TCP/IP properties (under IP Addresses > IPAll) and add that port to your firewall exceptions.
    • For quick testing, temporarily disable the firewall to confirm it’s the blocker.

Here’s the corrected connection string to start with (fixing the typo and using localhost for testing):

import pyodbc
# Confirm drivers are available
print(pyodbc.drivers())

# Corrected connection string
conn = pyodbc.connect(
    "Driver={ODBC Driver 17 for SQL Server};"
    "Server=localhost\FUHRP;"
    "Database=Fuhrp;"
    "Trusted_Connection=yes;"
)

If you still hit issues, try connecting with SQL Server Management Studio first. If SSMS can’t connect either, the problem lies with your SQL Server setup—not your Python code.

内容的提问来源于stack exchange,提问作者Heph

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.30 05:18:10