异常SQL server超时已过期



我的网站出现了一些问题。每天在我的网站繁忙的时候(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 server,而不是应用程序池,所以我不确定它是否与之链接。请注意,我有其他应用程序使用相同的数据库,当繁忙的应用程序出现超时时,它们将继续工作,不会出现任何问题,所以这可能暗示这与会话有关。

根据其他帖子的建议,我尝试将最大池大小更改为1024,但这无济于事。也许它太低了?

    <sessionState mode="SQLServer" allowCustomSqlDatabase="true" sqlConnectionString="Data Source=*********;Initial Catalog=*********;User ID=*********;Password=*********;Max Pool Size=1024;" cookieless="false" timeout="20"/>

有什么想法吗?

谢谢!

我的超时可以由长时间运行的sql产生,我注意到你使用的是一个没有参数的存储过程来选择数据,它返回的数据集有多大?

如果它足够大,就会产生超时。如果是这种情况,您必须引入where参数来处理具有较小结果集的查询。

最新更新