gpt4 book ai didi

.net - .net 中的连接池

转载 作者:行者123 更新时间:2023-12-02 13:01:33 24 4
gpt4 key购买 nike

Imports System.Data.SqlClient

Module Module1

Sub Main()
Dim iCount As Integer = 1
Try
Do
Dim sqlConn As New _
SqlConnection("Data Source=localhost;trusted_Connection=yes;initial catalog = MyDatabase;max pool size =100;")
sqlConn.Open()
Trace.WriteLine("opening connection " & CStr(iCount))
'sqlConn.Close()
'Trace.WriteLine("closing connection " & CStr(iCount))
'sqlConn.Dispose()
'Trace.WriteLine("disposing connection " & CStr(iCount))
iCount = iCount + 1
Loop Until iCount > 20000
Catch ex As Exception
Trace.WriteLine(ex.ToString)
End Try
End Sub

End Module

如果我执行此代码,此测试应用程序会在抛出 The timeout period elapsed before getting a connection from the pool 异常之前打开 115 个与数据库的连接。但应用程序池中只有 100 个连接。怎么可能?

最佳答案

猜测:由于您没有保存对打开连接对象的引用,因此前 15 个连接对象是否会被处置并重用?如果将连接推送到List<>,您还会得到115吗? ?

关于.net - .net 中的连接池,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5261360/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com