如何解决最大池大小 - ASP.NET

时间:2016-12-30 04:34:03

标签: sql-server vb.net ado.net connection-leaks

Public Function QueryDataSet(ByVal strSQL As String) As DataSet
    Dim ds As New DataSet
    Dim dtAdapter As New SqlDataAdapter
    objConn = New SqlConnection
    With objConn
        .ConnectionString = strConn
        .Open()
    End With
    objCmd = New SqlCommand
    With objCmd
        .Connection = objConn
        .CommandText = strSQL
        .CommandType = CommandType.Text
    End With
    dtAdapter.SelectCommand = objCmd
    dtAdapter.Fill(ds)

    objConn.Close()
    objConn.Dispose()
    SqlConnection.ClearPool(objConn)
    objConn = Nothing
    Return ds 
End function

以上是在班级

如何在我的服务器上修复解决最大池大小已满的功能?

请帮助我。

1 个答案:

答案 0 :(得分:0)

使用以下代码

Public Function QueryDataSet(ByVal strSQL As String) As DataSet
    Dim ds As New DataSet
    Dim dtAdapter As New SqlDataAdapter
Try
    objConn = New SqlConnection
    With objConn
        .ConnectionString = strConn
        .Open()
    End With
    objCmd = New SqlCommand
    With objCmd
        .Connection = objConn
        .CommandText = strSQL
        .CommandType = CommandType.Text
    End With
    dtAdapter.SelectCommand = objCmd
    dtAdapter.Fill(ds)

    objConn.Close()
    objConn.Dispose()
    SqlConnection.ClearPool(objConn)
    objConn = Nothing

Catch ex As Exception
MessageBox.Show(ex.Message)

Finally

    objConn.Close()
    objConn.Dispose()
    SqlConnection.ClearPool(objConn)
    objConn = Nothing

End Try

    Return ds 
End function

或在连接字符串中添加MaxPoolSize=abc