1

在此处输入图像描述我们有一个 Azure 应用服务,它尝试使用 VPN 经典(使用 VNET 配置)连接到本地 SQL 服务器。

有时我们会收到以下错误:

System.Data.SqlClient.SqlException (0x80131904):建立与 SQL Server 的连接时发生与网络相关或特定于实例的错误。服务器未找到或无法访问。验证实例名称是否正确以及 SQL Server 是否配置为允许远程连接。(提供者:TCP Provider,错误:0 - 等待操作超时。)---> System.ComponentModel.Win32Exception (0x80004005):等待操作超时

在 System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity 标识,SqlConnectionString connectionOptions,SqlCredential 凭据,对象 providerInfo,字符串 newPassword,SecureString newSecurePassword,布尔重定向用户实例,SqlConnectionString userConnectionOptions,SessionData reconnectSessionData,DbConnectionPool 池,字符串 accessToken,布尔 applyTransientFaultHandling)

在 System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions 选项,DbConnectionPoolKey poolKey,对象 poolGroupProviderInfo,DbConnectionPool 池,DbConnection owningConnection,DbConnectionOptions userOptions)

在 System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool 池,DbConnection owningObject,DbConnectionOptions 选项,DbConnectionPoolKey poolKey,DbConnectionOptions 用户选项)

在 System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject,DbConnectionOptions userOptions,DbConnectionInternal oldConnection)

在 System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject,DbConnectionOptions userOptions,DbConnectionInternal oldConnection)

在 System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject,UInt32 waitForMultipleObjectsTimeout,布尔allowCreate,布尔onlyOneCheckConnection,DbConnectionOptions userOptions,DbConnectionInternal& 连接)

在 System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject,TaskCompletionSource`1 重试,DbConnectionOptions userOptions,DbConnectionInternal& 连接)

在 System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection,TaskCompletionSource`1 重试,DbConnectionOptions userOptions,DbConnectionInternal oldConnection,DbConnectionInternal& 连接)

在 System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection,DbConnectionFactory connectionFactory,TaskCompletionSource`1 重试,DbConnectionOptions userOptions)

在 System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection,DbConnectionFactory connectionFactory,TaskCompletionSource`1 重试,DbConnectionOptions userOptions)

在 System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 重试)

在 System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 重试)

在 System.Data.SqlClient.SqlConnection.Open()

在 Dapper.SqlMapper.d__11`1.MoveNext()

在 System.Collections.Generic.List 1..ctor(IEnumerable1 集合)

在 System.Linq.Enumerable.ToList[TSource](IEnumerable`1 源)

在 Dapper.SqlMapper.Query[T](IDbConnection cnn, String sql, Object param, IDbTransaction transaction, Boolean buffered, Nullable 1 commandTimeout, Nullable1 commandType)

在 SiSystems.ClientApp.Web.Domain.Repositories.UserRepository.FindByPrimaryEmail(字符串用户名)

在 SiSystems.ClientApp.Web.Domain.Repositories.UserRepository.FindByName(字符串用户名)

在 SiSystems.ClientApp.Web.Auth.UserStore.<>c__DisplayClass3_0.b__0()

在 System.Threading.Tasks.Task`1.InnerInvoke()

在 System.Threading.Tasks.Task.Execute()

--- 从先前抛出异常的位置结束堆栈跟踪 ---

在 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)

在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)

在 Microsoft.AspNet.Identity.TaskExtensions.CultureAwaiter`1.GetResult()

在 Microsoft.AspNet.Identity.UserManager`2.d__12.MoveNext()

--- 从先前抛出异常的位置结束堆栈跟踪 ---

在 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)

在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)

在 SiSystems.ClientApp.Web.Auth.ApplicationOAuthProvider.d__2.MoveNext()

--- 从先前抛出异常的位置结束堆栈跟踪 ---

在 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)

在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)

在 Microsoft.Owin.Security.OAuth.OAuthAuthorizationServerHandler.d__3f.MoveNext()

--- 从先前抛出异常的位置结束堆栈跟踪 ---

在 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)

在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)

在 System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(任务任务)

在 Microsoft.Owin.Security.OAuth.OAuthAuthorizationServerHandler.d__22.MoveNext()

--- 从先前抛出异常的位置结束堆栈跟踪 ---

在 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)

在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)

在 System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(任务任务)

在 Microsoft.Owin.Security.OAuth.OAuthAuthorizationServerHandler.d__0.MoveNext()

--- 从先前抛出异常的位置结束堆栈跟踪 ---

在 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)

在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)

在 Microsoft.Owin.Security.Infrastructure.AuthenticationMiddleware`1.d__0.MoveNext()

--- 从先前抛出异常的位置结束堆栈跟踪 ---

在 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)

在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)

在 Microsoft.Owin.Security.Infrastructure.AuthenticationMiddleware`1.d__0.MoveNext()

--- 从先前抛出异常的位置结束堆栈跟踪 ---

在 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)

在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)

在 Microsoft.Owin.Security.Infrastructure.AuthenticationMiddleware`1.d__0.MoveNext()

--- 从先前抛出异常的位置结束堆栈跟踪 ---

在 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)

在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)

在 Microsoft.AspNet.Identity.Owin.IdentityFactoryMiddleware`2.d__0.MoveNext()

--- 从先前抛出异常的位置结束堆栈跟踪 ---

在 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)

在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)

在 Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.IntegratedPipelineContextStage.d__5.MoveNext()

--- 从先前抛出异常的位置结束堆栈跟踪 ---

在 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)

在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)

在 Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.IntegratedPipelineContext.d__2.MoveNext()

--- 从先前抛出异常的位置结束堆栈跟踪 ---

在 Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.StageAsyncResult.End(IAsyncResult ar)

在 Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.IntegratedPipelineContext.EndFinalWork(IAsyncResult ar)

在 System.Web.HttpApplication.AsyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()

在 System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep 步骤)

在 System.Web.HttpApplication.ExecuteStep(IExecutionStep 步骤,Boolean& completedSynchronously)

ClientConnectionId:00000000-0000-0000-0000-000000000000

错误号:258,状态:0,类:20

添加了我从 azure 获得的日志图像

4

1 回答 1

3

1- 这可能是由于未在应用程序的连接字符串中的 db-server-name 上指定 tcp 协议引起的。

第二种可能性:

2- 转到 Sql Server 配置管理-> SQL Server 网络配置-> 'servername' 的协议并检查命名管道是否已启用。

3-防火墙规则:

TCP 端口 1433 的端口例外。在“新建入站规则向导”对话框中,使用以下信息创建端口例外: 选择端口 选择 TCP 并指定端口 1433 允许连接 选择所有三个配置文件(域、私有和公共)规则“SQL – TCP 1433” UDP 端口 1434 的端口例外。再次单击新建规则并使用以下信息创建另一个端口例外: 选择端口 选择 UDP 并指定端口 1434 允许连接 选择所有三个配置文件(域、私有和公共)将规则命名为“SQL – UDP 1434 sqlservr.exe 的程序异常。再次单击新建规则并使用以下信息创建程序例外:选择程序单击浏览以在此位置选择“sqlservr.exe”:[C:\Program Files\Microsoft SQL Server\MSSQL11.\MSSQL\Binn\sqlservr. exe] 其中是您的 SQL 实例的名称。允许连接 选择所有三个配置文件(域、私有和公共) 将规则命名为 SQL – sqlservr.exe sqlbrowser.exe 的程序例外 再次单击新建规则并使用以下信息创建另一个程序例外: 选择程序 单击浏览以选择此位置的 sqlbrowser.exe:[C:\Program Files\Microsoft SQL Server\90\Shared\sqlbrowser.exe]。允许连接 选择所有三个配置文件(域、私有和公共) 将规则命名为 SQL - sqlbrowser.exe 此位置的 exe:[C:\Program Files\Microsoft SQL Server\90\Shared\sqlbrowser.exe]。允许连接 选择所有三个配置文件(域、私有和公共) 将规则命名为 SQL - sqlbrowser.exe 此位置的 exe:[C:\Program Files\Microsoft SQL Server\90\Shared\sqlbrowser.exe]。允许连接 选择所有三个配置文件(域、私有和公共) 将规则命名为 SQL - sqlbrowser.exe

请参阅:SQL 连接错误:System.Data.SqlClient.SqlException (0x80131904) 以及:https ://thycotic.force.com/support/s/article/System-Data-SqlClient-SqlException-0x80131904

于 2018-01-22T23:59:41.180 回答