【发布时间】:2017-02-07 09:35:30
【问题描述】:
我正在尝试移植一个充当 SQL Server 数据库前端的 Web api。 Web api 在 Windows 下运行良好,当部署到 IIS 时,在 Windows 上的 .Net Core 上运行,但在 OSX 或 Linux 中运行时会出现连接错误。
在 Windows 的 Visual Studio 中工作的连接字符串是
connectionString="data source=A\B;initial catalog=C;
persist security info=True;user id=X; password=Y;
MultipleActiveResultSets=True;App=EntityFramework"
providerName="System.Data.SqlClient"
然后将其转换为 .Net 核心变体的连接字符串:
Server=A\B;Database=C;user id=X;password=Y;
该项目编译良好,甚至可以在 Windows 的 .Net 内核下运行,但在 *nix 机器上运行时会崩溃。
错误是:
Unhandled Exception: System.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: 35 - An internal exception was caught) --->
System.AggregateException: One or more errors occurred. (No such device
or address) --->
System.Net.Internals.SocketExceptionFactory+ExtendedSocketException: No
such device or address
我可以 ping 地址,但我猜有效地址 (A) 和服务器实例 (B) 的组合不适用于 *nix 下的简单斜线。
【问题讨论】:
-
你说崩溃。实际发生了什么?您的 Mac 是否能够解析名称 A 以指向正确的机器?
-
我用更好的描述更新了这个问题。无论如何,我的机器确实可以ping通A,所以错误可能是A\B的组合,应该以其他方式给出?
-
什么是
A? IP 地址、FQDN、服务器名称?您可以使用任何其他工具连接到服务器吗?仅仅因为您可以 ping 一个地址并不意味着您可以连接到一个命名实例。
标签: sql-server .net-core