【发布时间】:2020-08-18 00:12:36
【问题描述】:
我在 ASP.NET 中的 Web 应用程序出现问题。
我的错误是:
连接没有关闭连接的当前状态是打开
当两个客户端都在连接字符串中提交请求时。
这是我的代码:
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
Throw ex
Finally
conn.Close()
End Try
End Sub
如何处理我的连接字符串可以处理的多个请求?
请帮忙!
谢谢!
【问题讨论】:
-
为什么要在异常块和 finally 代码块中关闭连接?只有一次接近就足够了,最后是。
-
我的错误。但是在那次尝试中,它仍然没有在最后部分关闭连接。错误仍然是连接没有关闭连接的当前状态是打开
标签: c# asp.net sql-server ado.net connection-string