[研究][ASP.NET]SQL Server 連線數量測試(四)Close、Dispose、ClearPool 與 ClearAllPools
2022-05-03
環境:Visual Studio 2022 + ASP.NET + WebForm + Web Application + C# + SQL Server 2019
********************************************************************************
SQL Server Management Studio 上執行
SELECT c.session_id, c.connect_time, s.login_time, c.client_net_address, s.login_name, s.status FROM sys.dm_exec_connections c left join sys.dm_exec_sessions s on c.session_id = s.session_id WHERE login_name='testuser'; |
using System; using System.Data.SqlClient; using System.Web.Configuration; namespace WebApplication1 { public partial class Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { string queryString = @"SELECT * FROM [Table1];"; using (SqlConnection connection = new SqlConnection( WebConfigurationManager.ConnectionStrings["TestDBConnectionString"].ConnectionString)) { SqlCommand command = new SqlCommand(queryString, connection); connection.Open(); command.ExecuteNonQuery(); } } } } |
********************************************************************************
Default.aspx.cs
using System;
using System.Data.SqlClient;
using System.Web.Configuration;
namespace WebApplication1
{
public partial class Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string queryString = @"SELECT * FROM [Table1];";
using (SqlConnection connection = new SqlConnection(
WebConfigurationManager.ConnectionStrings["TestDBConnectionString"].ConnectionString))
{
SqlCommand command = new SqlCommand(queryString, connection);
connection.Open();
command.ExecuteNonQuery();
connection.Close();
}
}
}
}
|
********************************************************************************
Default.aspx.cs
using System;
using System.Data.SqlClient;
using System.Web.Configuration;
namespace WebApplication1
{
public partial class Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string queryString = @"SELECT * FROM [Table1];";
using (SqlConnection connection = new SqlConnection(
WebConfigurationManager.ConnectionStrings["TestDBConnectionString"].ConnectionString))
{
SqlCommand command = new SqlCommand(queryString, connection);
connection.Open();
command.ExecuteNonQuery();
connection.Close();
connection.Dispose();
//SqlConnection.ClearPool(connection);
//SqlConnection.ClearAllPools();
}
}
}
}
|
Default.aspx.cs
using System;
using System.Data.SqlClient;
using System.Web.Configuration;
namespace WebApplication1
{
public partial class Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string queryString = @"SELECT * FROM [Table1];";
using (SqlConnection connection = new SqlConnection(
WebConfigurationManager.ConnectionStrings["TestDBConnectionString"].ConnectionString))
{
SqlCommand command = new SqlCommand(queryString, connection);
connection.Open();
command.ExecuteNonQuery();
connection.Close();
connection.Dispose();
SqlConnection.ClearPool(connection);
//SqlConnection.ClearAllPools();
}
}
}
}
|
Default.aspx.cs
using System; using System.Data.SqlClient; using System.Web.Configuration; namespace WebApplication1 { public partial class Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { string queryString = @"SELECT * FROM [Table1];"; using (SqlConnection connection = new SqlConnection( WebConfigurationManager.ConnectionStrings["TestDBConnectionString"].ConnectionString)) { SqlCommand command = new SqlCommand(queryString, connection); connection.Open(); command.ExecuteNonQuery(); connection.Close(); connection.Dispose(); SqlConnection.ClearPool(connection); SqlConnection.ClearAllPools(); } } } } |
相關
[研究][ASP.NET]SQL Server 連線數量測試(四)Close、Dispose、ClearPool 與 ClearAllPools
https://shaurong.blogspot.com/2022/05/aspnetsql-server-closedisposeclearpool.html
[研究][ASP.NET]SQL Server 連線數量測試(三)連線歸屬測試
https://shaurong.blogspot.com/2022/05/aspnetsql-server_44.html
[研究][ASP.NET]SQL Server 資料庫連線數量測試(二)資料庫中儲存的連線資訊https://shaurong.blogspot.com/2022/05/aspnetsql-server_3.html
[研究][ASP.NET]SQL Server 連線數量測試(一)程式與資料庫連線數量https://shaurong.blogspot.com/2022/05/aspnetsql-server.html
沒有留言:
張貼留言