提供者:SSL Provider,错误:0-远程主机强行关闭了现有连接

问题描述 投票:0回答:1

简而言之,我编写了一个控制台应用程序,该应用程序仅在SQL Server数据库中调用存储过程。然后设置一个Windows Task Scheduler事件,以每5分钟调用一次控制台应用程序的.exe文件。在大多数情况下,它可以正常工作,但是一天大约运行10次左右,因此,只要打开连接以调用存储过程,就会得到以下sqlException:

System.Data.SqlClient.SqlException (0x80131904): A connection was successfully established with the server, 
but then an error occurred during the login process. 
(provider: SSL Provider, error: 0 - An existing connection was forcibly closed by the remote host.) 

我已经在一个try块中临时建立了一个简单的5次重试,并且之间有短暂的暂停,这对某些人有所帮助,但是每天仍然有几次失败,这5次都失败了。我认为这一定是某种沟通问题,但我什至不知道在哪里看。

我完成的大部分研究都针对TLS或防火墙问题。我不是这两个方面的专家,但我想如果这两个原因中的任何一个都会始终导致错误。与SSL相同。另一方面,出于相同的原因,我看不到控制台应用程序或存储过程可能是编码问题,所以我没有主意。

SQL连接代码类似于以下内容:


    Public Function GetDataTable(tsql As String, Optional ConnectionString As String = Nothing, Optional TryNum As Integer = 1) As DataTable
        Try
            Dim dt As DataTable
            Using conn As SqlConnection = New SqlConnection(If(Not ConnectionString Is Nothing, ConnectionString, SConn))
                conn.Open()
                Using dr As SqlDataReader = (New SqlCommand With {.CommandType = CommandType.Text, .CommandText = tsql, .Connection = conn, .CommandTimeout = SqlCommandTimeout}).ExecuteReader
                    dt = New DataTable()
                    dt.Load(dr)
                    dr.Close()
                End Using
                conn.Close()
            End Using
            Return dt
        Catch exSQL As System.Data.SqlClient.SqlException
            If exSQL.ToString.Contains("A connection was successfully established with the server, but then an error occurred during the login process.") AndAlso TryNum < MaxTries Then
                Threading.Thread.Sleep(RetryWaitMS)
                Return GetDataTable(tsql, ConnectionString, TryNum + 1)
            Else
                SendMsg(ERROR_EMAIL_GROUP, ERROR_EMAIL_GROUP, "CommonUtils - SQL Error", tsql & vbCrLf & exSQL.ToString)
                Throw exSQL
            End If
        End Try
    End Function

请先不要使用Parameters.AddWithValue等和SQL注入。

sql ssl sqlexception
1个回答
0
投票

我有一个定期使用Windows任务调度程序安排的powerhshell脚本使用相同的例外,大多数情况下,每天仅会例外。您已经有解决方案了吗?

© www.soinside.com 2019 - 2024. All rights reserved.