【发布时间】:2020-08-23 09:08:12
【问题描述】:
背景: 我正在使用最新的 4.8 ASP 网络容器将应用程序移植到 docker 容器。它们都使用 SQL Server 连接。
App1:Framework 4.8,完全没有问题。 App2:Framework 4.6.2,根本无法与SQL Server建立连接。
这是连接字符串:
<add name="DefaultConnection" connectionString="Data Source=172.31.0.2; Initial Catalog=Integ_Catalog; User ID=MYUSER; Password=Pa55W0rd; MultipleActiveResultSets=True;Connect Timeout=120" providerName="System.Data.SqlClient" />
在容器中,我运行了 Powershell 来验证连接字符串是否 100% 正常工作。我已将 dapper 更新到最新版本,希望对您有所帮助。有什么想法可以尝试吗?
追踪
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: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server) ---> System.ComponentModel.Win32Exception (0x80004005): The network path was not found
at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection)
at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection)
at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
at System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
at System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry)
at System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry)
at System.Data.SqlClient.SqlConnection.Open()
* 更新 *
当应用程序与数据库位于同一 AWS VPC 中时,调用将失败。但是当他们在不同的 VPC 中时,它会起作用。这是没有意义的,你会认为它会反过来。数据库、应用程序/主机和 VPC 内的网络看起来很好。
【问题讨论】:
-
你得到的错误信息是什么?
-
如果它适用于 .NET Framework 4.8 但不适用于 4.6.2,我会怀疑 TLS 1.2 连接问题。确认 app2 实际上是针对 .NET Framework 4.6.2(4.6.2 及更高版本支持 TLS 1.2)而构建的,并查找对可能试图配置 SSL 3.0、TLS 1.0 或 TLS 1.1 连接的
System.Net.SecurityProtocolType的任何引用(所有这些都已弃用)。 -
.NET 框架差异不应导致任何错误。它可能是其他东西,启用跟踪和获取堆栈跟踪将是理想的。
-
我添加了跟踪,谢谢。
-
检查服务器是否启用了 TCP/IP。 (在 SQL Server 配置管理器中)或任何其他可能阻止您的连接的(防火墙)。客户端认为它找不到服务器,错误 0x80004005 通常与某种形式的拒绝有关。两者之间存在连接加密差异的可能性吗?
标签: asp.net sql-server docker iis containers