コードを見ることなく、決定的な回答をすることは不可能です。データベースの接続をすばやく整理しているわけではない場合は、はとなります。
次のような何かをしている場合:
While(True)
Dim con as new SqlConnection(connectionString)
con.Open()
Dim cmd as New SqlCommand("usp_getJob", con)
cmd.CommandType = CommandType.StoredProcedure
Dim dr as SqlDataReader = cmd.ExecuteReader(CommandBehavior.SingleResult Or CommandBehavior.SingleRow Or CommandBehavior.CloseConnection)
If(dr.Read())
DoSomething(dr)
Else
Thread.Sleep(10)
End If
End While
...それはより速く、彼らが自分で離れて行くよりも、接続を開きます。
あり、いくつかの交互である、と私は接続が可能な限り高速に接続プールに戻すことができるようにUsing
ブロックを使用して主張したい:
While(True)
Using con as new SqlConnection(connectionString)
con.Open()
Using cmd as New SqlCommand("usp_getJob", con)
cmd.CommandType = CommandType.StoredProcedure
Using dr as SqlDataReader = cmd.ExecuteReader(CommandBehavior.SingleResult Or CommandBehavior.SingleRow Or CommandBehavior.CloseConnection)
If(dr.Read())
DoSomething(dr)
dr.Close()
Else
Thread.Sleep(10)
End If
End Using
End Using
End Using
End While
これらは、その後、SqlDataReader
にDispose()
を呼び出します、SqlConnection
そしてSqlCommand
- 最初の2つのどちらかで接続プールに接続が解放されます(これはSqlDataReader
にあり、終了時にはCloseConnection
になります)
何が起こっているかを見るためにコードスニペットを投稿する機会はありますか? – twlichty