我有一个非常简单的服务,它一直在早期工作,但现在我将它升级到更新的 .NET 版本,它已经停止工作,出现如下错误消息:
超时已过。在从池中获取连接之前超时时间已过。这可能是因为所有池连接都在使用中并且达到了最大池大小。
我试图执行服务尝试运行的存储过程,并在 ms sql server management studio 中直接运行它需要不到 1 秒,所以我不明白可能是什么问题?使用相同数据库的客户端(虽然不是相同的存储过程)在同时使用它们时没有任何超时问题。
编辑所以你可以看到代码:
这在服务启动时调用:
Private Sub SetupGetBatch1Command()
GetBatch1Command = New System.Data.SqlClient.SqlCommand("spgetTheData1")
GetBatch1Command.CommandType = Data.CommandType.StoredProcedure
End Sub
这有时间间隔:
Private Function GetBatch1() As DataSet
Dim dataset As New DataSet
Dim adapter As Data.SqlClient.SqlDataAdapter
Dim cn As New System.Data.SqlClient.SqlConnection(connectionstring())
GetBatch1Command.Connection = cn
adapter = New Data.SqlClient.SqlDataAdapter(GetBatch1Command)
adapter.Fill(dataset)
Return dataset
End Function
我没有这样做,也不太了解它,但我想我至少应该遵循以下建议并在某处添加 cn.dispose() ?
还有其他类似的数据库连接,都以与上面示例完全相同的方式完成。