同时有多个请求时的连接字符串错误

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

我在ASP.NET的Web应用程序中遇到问题。

当两个客户端都在连接字符串中提交请求时,我的错误是The connection was not closed the connection's current state is open。>>

这是我的代码:

Public Sub populateGrid(ByVal sql As String, ByVal grd As GridView)
    Try
        cmd = New SqlCommand(sql)
        da = New SqlDataAdapter(sql, conn)
        conn.Open()
        ds = New DataSet
        da.Fill(ds)
        grd.DataSource = ds
        grd.DataBind()
        conn.Close()
    Catch ex As Exception
        conn.Close()
        Throw ex
    Finally
        conn.Close()
    End Try
End Sub

如何处理连接字符串可以处理的多个请求?

请帮助!

谢谢!

我在ASP.NET的Web应用程序中遇到问题。我的错误是两个客户端在连接字符串中提交请求时,连接未关闭,连接的当前状态为打开。 ...

asp.net sql-server connection-string
1个回答
0
投票

如下所示,您可以在打开连接之前检查连接是否已经打开。

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