ADO.NET连接池写法
using System; using System.Data; using System.Data.SqlClient; class Program { static void Main() { // 连接字符串,其中包含连接池的配置 string connectionString = "Server=mySqlServerAddress;Database=myDataBase;Integrated Security=True;Max Pool Size=10;"; // 使用using语句确保连接被正确关闭和释放 using (SqlConnection connection = new SqlConnection(connectionString)) { // 打开连接 connection.Open();
using (SqlCommand sqlCommand_0 = new SqlCommand())
{
// 这里可以执行数据库操作 // ... } } // 使用结束时,连接自动关闭并返回到连接池 } }
主要是连接串里Max Pool Size的配置和using的使用。
hello,world~~~
![](https://files-cdn.cnblogs.com/files/thingk/%E5%BE%AE%E4%BF%A1%E6%94%B6%E6%AC%BE%E7%A0%81.bmp)