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

Docker SQL Server容器与Entity Framework Core连接失败求助

连接Docker容器中SQL Server失败问题

我使用以下命令创建SQL Server容器:

docker run -e "ACCEPT_EULA=Y" -e "MSSQL_SA_PASSWORD=********" -e "MSSQL_PID=Evaluation" -p 1433:1433  --name sqlserver --hostname sqlserver -d mcr.microsoft.com/mssql/server:2022-preview-ubuntu-22.04

我的连接字符串如下:

"Server=localhost,1433;Database=TemplateDb;User Id=sa;Password=********;Integrated Security=false;TrustServerCertificate=true"

连接时抛出异常:

Microsoft.Data.SqlClient.SqlException: 'A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: TCP Provider, error: 40 - Could not open a connection to SQL Server: Could not open a connection to SQL Server)'

已确认的信息和尝试的操作:

  • 使用Management Studio或Azure Data Studio可正常连接该容器,数据库已创建
  • 已尝试重启容器、检查防火墙设置
  • 通过docker exec可连接容器,docker ps显示容器正在运行

内容的提问来源于stack exchange,提问作者Ondřej Halata

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.13 04:20:54