【发布时间】:2016-02-29 13:07:22
【问题描述】:
我的网站遇到了一些问题。每天在我网站的繁忙时间(300-400 个并发用户),用户开始收到很多“超时已过期”错误消息。网页通常每隔几个小时就会挂起并超时 2-3 分钟。
在不明确的情况下,收到的错误消息只是“超时已过期”,但有时它们会附带更多关于最大池大小的信息。我不确定这是池大小还是只是超时的症状。
System.Web.HttpException (0x80004005): Unable to connect to SQL Server session database. --->
System.InvalidOperationException: Timeout expired.
The timeout period elapsed prior to obtaining a connection from the pool.
This may have occurred because all pooled connections were in use and max pool size was reached.
这是我的 DB 函数的示例:
Public Function StoredProcedureDataSet(ByVal strStoredProcedureName As String, ByVal cmd As SqlClient.SqlCommand) As DataSet
cmd.CommandType = CommandType.StoredProcedure
cmd.CommandText = strStoredProcedureName
cmd.Connection = conn
cmd.CommandTimeout = 0
Dim objDA As New System.Data.SqlClient.SqlDataAdapter
Dim objDataSet As New DataSet
Try
conn.Open()
objDA.SelectCommand = cmd
objDA.Fill(objDataSet)
Catch ex As Exception
Throw ex
Finally
StoredProcedureDataSet = objDataSet
conn.Close()
cmd.Dispose()
objDataSet.Dispose()
End Try
End Function
我确保连接在 Try 中打开并在 finally 中关闭,所以我无法让连接保持打开状态。
我在会话而不是应用程序池中使用 SQL 服务器,所以我不确定它是否与此相关联。请注意,我有其他应用程序使用相同的数据库,当繁忙的应用程序发生超时时,它们将继续工作而不会出现任何问题,因此这可能暗示这与会话有关。
根据其他帖子的建议,我尝试将最大池大小更改为 1024,但没有帮助。也许它太低了?
<sessionState mode="SQLServer" allowCustomSqlDatabase="true" sqlConnectionString="Data Source=*********;Initial Catalog=*********;User ID=*********;Password=*********;Max Pool Size=1024;" cookieless="false" timeout="20"/>
有什么想法吗?
谢谢!
【问题讨论】:
-
我猜你添加的
Max pool size可能有问题。试试这个并检查Max Pool Size=100
标签: asp.net sql-server vb.net sql-server-2012 timeout