問題
.NET 6 透過 System.Data.SqlClient 連接資料庫,想要在 Performance Monitor 中加入 .NET Data Provider for SqlServer 來查看 Connection Pool 的相關資料,但是在 Instances of selected object: 中,卻找不到對應的 Process Id
在 .NET 6 可以透過 dotnet-counters 來查看Microsoft.Data.SqlClient,而不是System.Data.SqlClient
解法
Performance Monitor 工具是查看 .NET Framework 的程式,.NET 6 要使用 dotnet-counters 。
但是dotnet-counters可以看的是Microsoft.Data.SqlClient的 EventCounters。
1.安裝 Microsoft.Data.SqlClient 套件(5.2.3)
2.調整 System.Data.SqlClient Namespace
將 System.Data.SqlClient Namespace 改成 Microsoft.Data.SqlClient Namespace
3.重新建置
dotnet-counters monitor
1.安裝dotnet-countersdotnet tool install --global dotnet-counters --version 6.0.327302
2.查看可以 monitor 的 processdotnet-counters ps
- 請確定程式已經在執行
3.監看 Microsoft.Data.SqlClient.EventSourcedotnet-counters monitor --counters Microsoft.Data.SqlClient.EventSource -p <process-id> --refresh-interval 3
也可以將資料存成 CSV /JSON 格式,例如,dotnet-counters collect --counters Microsoft.Data.SqlClient.EventSource --process-id <process-id> --refresh-interval 3 --format csv
參考資源
Timeout expired. all pooled connections were in use and max pool size was reached. 自動關閉 Connection ?
已超過連接逾時的設定。在取得集區連接之前超過逾時等待的時間,可能的原因為所有的共用連接已在使用中,並已達共用集區大小的最大值。
dotnet-counters