【问题标题】:Issues with SQL Connection from an IIS ASP.NET container来自 IIS ASP.NET 容器的 SQL 连接问题
【发布时间】: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


【解决方案1】:

您需要在 SQL Server 中添加 IIS_USR 并需要授予访问数据库的权限

【讨论】:

    【解决方案2】:

    解决方案是将应用程序移至外部 VPC,为什么?世界可能永远不会知道:)

    【讨论】:

    • 您的路由和防火墙配置是什么?
    • 它是敞开的
    猜你喜欢
    • 2017-01-24
    • 1970-01-01
    • 2021-12-10
    • 1970-01-01
    • 2015-11-19
    • 1970-01-01
    • 2016-05-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多