SqlSugar.SqlSugarException: 中文提示 : 连接数据库过程中发生错误,检查服务器是否正常连接 返回
jz 发布于2026/2/2
SqlSugar.SqlSugarException: 中文提示 : 连接数据库过程中发生错误,检查服务器是否正常连接字符串是否正确,错误信息: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)DbType="SqlServer";ConfigId="".
English Message : Connection open error . 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)DbType="SqlServer";ConfigId=""
at SqlSugar.Check.Exception(Boolean isException, String message, String[] args)
at SqlSugar.AdoProvider.CheckConnection()
at SqlSugar.SqlServerProvider.GetCommand(String sql, SugarParameter[] parameters)
at SqlSugar.AdoProvider.GetDataReader(String sql, SugarParameter[] parameters)
at SqlSugar.QueryableProvider`1.GetData[TResult](KeyValuePair`2 sqlObj)
at SqlSugar.QueryableProvider`1._ToList[TResult]()
at SqlSugar.QueryableProvider`1.ToList()
谁遇到过这个问题,我本地Asp.Net Core WebApi 连接docker容器中的sqlserver数据库,提示这个错误,本地控制台应用程序用SqlSugar连接docker容器中的sqlserver数据库,又能连上,api里确连不上,有没有知道这是什么原因造成的呢?
热忱回答(2)
-
fate sta VIP0
2026/2/2可能的原因
未在 SQL Server 上启用 TCP/命名管道协议
建议的解决方案:在 SQL Server 配置管理器控制台的 SQL Server 实例上启用 TCP/命名管道协议。
主机名未知
建议的解决方案:确保主机名从启动连接的客户端解析为服务器的 IP 地址。
0 回复 -
fate sta VIP0
2026/2/2https://learn.microsoft.com/zh-cn/sql/connect/ado-net/sqlclient-troubleshooting-guide?view=sql-server-ver15
0 回复