【发布时间】:2015-06-15 03:12:35
【问题描述】:
我在Parallel.ForEach 中使用Npgsqlconnection,循环遍历列表中的内联查询。
当我达到 1400+ 左右的数字时,我得到一个异常提示
'致命:53300:剩余的连接槽保留用于非复制超级用户连接'。
我正在使用
Pooling=true;MinPoolSize=1;MaxPoolSize=1024;ConnectionLifeTime=1
在我的 app.config 和 con.Close()、con.ClearPool()、con.Dispose() 在我的代码中。
Parallel.ForEach(查询,查询 => { 使用 (NpgsqlConnection con = new NpgsqlConnection(ConfigurationManager.ConnectionStrings["PSQL"].ConnectionString)) { con.ClearPool(); con.Open();
//int count = 0;
int queryCount = queries.Count;
using (NpgsqlCommand cmd = con.CreateCommand())
{
cmd.CommandType = CommandType.Text;
//cmd.CommandTimeout = 0;
cmd.CommandText = query;
cmd.ExecuteNonQuery();
count += 1;
this.label1.Invoke(new MethodInvoker(delegate { this.label1.Text = String.Format("Processing...\n{0} of {1}.\n{2}% completed.", count, queryCount, Math.Round(Decimal.Divide(count, queryCount) * 100, 2)); }));
}
con.Close();
//con.Dispose();
//con.ClearPool();
}
});
【问题讨论】:
-
您能发布导致问题的代码吗?没有它,就很难为您提供帮助。
标签: c# postgresql npgsql parallel.foreach