请考虑一段代码:
static string GetUser(int id)
{
Console.WriteLine("Start get -> {0}", id);
var connb = new DB2ConnectionStringBuilder(ConfigurationManager.ConnectionStrings["DB2_USER"].ConnectionString);
connb.Pooling = true;
connb.MinPoolSize = 10;
connb.MaxPoolSize = 100;
var conn = new DB2Connection(connb.ConnectionString);
var cmd = new DB2Command("SELECT name FROM USR.USERS WHERE id = @id");
cmd.Parameters.Add("@id", id);
cmd.Connection = conn;
conn.Open();
// conn.IsConnectionFromPool <-- false
var reader = cmd.ExecuteReader();
var result = string.Empty;
while(reader.Read())
result = reader.GetString(0);
conn.Close();
conn.Dispose();
Console.WriteLine("End get <- {0} {1}", id, result);
return result;
}
此示例中使用了 IBM .NET 数据库驱动程序。
尽管连接字符串明确定义了连接池设置,但 IsConnectionFromPool 属性永远不会为真。
这真的意味着数据库驱动程序不为我的情况维护池吗?是否应该针对这种情况以某种方式调整 .NET 驱动程序设置?