【发布时间】:2020-01-21 18:30:58
【问题描述】:
我的新申请页面在获得一些流量后每隔一小时左右就会出现一次超时错误,我所说的流量是指用户提交 5-10 个申请。如何找到连接被捆绑的原因?
这在过去一直是个问题,所以每当我使用 sql 数据读取器对象时,我都会确保实现“Using”语句。我还确保在处理数据读取器之前线程不会中止。我怀疑我对数据阅读器的使用是问题所在,所以也许是我的非查询代码导致了问题,但我不明白为什么。
我还为我的下拉列表控件使用了一些 sqldatasource 对象,据我所知,这不会是我的问题的根源。
查看代码示例了解我如何使用我的 sql 对象。
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Using drApp As SqlDataReader = LookupAppByID()
'some code
drApp.Close()
End Using
End Sub
Public Function LookupAppByID() As SqlDataReader
Dim Command As New SqlClient.SqlCommand
Command.Connection = GetDBConnection()
Command.CommandType = CommandType.Text
Command.CommandText = "select statement"
Return Command.ExecuteReader(CommandBehavior.CloseConnection)
End Function
Public Function UpdateAppStatus() As Integer
UpdateAppStatus = 0
Using Command As New SqlClient.SqlCommand("update statement", GetDBConnection())
UpdateAppStatus = Command.ExecuteNonQuery()
Command.Connection.Close()
Command.Connection.Dispose()
Command.Dispose()
End Using
End Function
Public Function GetDBConnection() As SqlClient.SqlConnection
Dim connection As New SqlClient.SqlConnection
connection.ConnectionString = "connection string"
connection.Open()
Return connection
End Function
显然,我希望它能够顺利运行,但是当用户开始点击该页面时,它会收到此错误:超时已过期。在从池中获取连接之前超时时间已过。这可能是因为所有池连接都在使用中并且已达到最大池大小。
我的代码有问题吗? 如何缩小导致此问题的原因?
【问题讨论】:
标签: asp.net vb.net timeout sqlconnection application-pool