[英]Allow multiple active connections to MS SQL database using VS datasets
因此,我在ASP.Net網站上使用了Visual Basic數據集,當多個用戶訪問該網站時,我得到了類似的信息:
ExecuteReader需要打開且可用的連接。 連接的當前狀態為“打開”。
我可以創建與SQL數據庫的多個連接嗎?
我知道數據集后面有普通代碼,所以我想知道是否可以修改這些文件中的內容以為每個用戶會話創建新連接。
我標記了c#,因為如果在c#中彈出答案,我將其轉換為...
在像ASP.NET這樣的多線程,多用戶環境中,您必須遠離共享連接。 最好根據需要創建連接,然后再處理它。 在后台,.NET將使用連接池,而SQL Server在處理大量的多個連接時將沒有任何問題。 偽代碼:
' SQLCommand to fill DataTable
Dim dt As New DataTable
Using cnn As New SqlConnection("someconnectionstring")
Dim cmd As New SqlCommand("SELECT * FROM SomeTable", cnn)
cnn.Open()
dt.Load(cmd.ExecuteReader)
cnn.Close()
End Using
' TableAdapter to fill DataSet
Dim ds As New DataSet
Dim ta As New SqlDataAdapter
ta.Fill(ds)
The [Using statement][1] lets .NET handle the disposal of the connection for you.
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.