【发布时间】:2016-03-14 18:18:41
【问题描述】:
我一直在研究这个问题,这是我用来强制连接超时的场景:
在 PostgreSQL 中,我已将 postgres.conf 更改为将其超时设置为 10 毫秒。
statement_timeout = 10
下面是重要的代码:
var conn = new OleDbConnection(connectionString);
var da = new OleDbDataAdapter(sql, conn);
var dt = new DataTable();
var result = da.Fill(dt);
这里是连接字符串的内容:
"Provider=PGNP.1;Password=****;Persist Security Info=True;User ID=****;Initial Catalog=****;Data Source=localhost;Extended Properties=\"SSL=allow;\""
发生超时时,不会抛出任何错误或异常,dt.Rows.Count 会显示 0 作为结果。
当我将 postgres.conf 文件改回 statement_timeout = 0(禁用它)时,dt.Rows.Count 的结果大于 0。
当他实际遇到超时错误时告诉用户他“没有结果”实在是太糟糕了。
有什么想法吗?
【问题讨论】:
-
根据PGSQL Docs 不建议在postgresql.conf 中设置statement_timeout,因为它会影响所有会话。 也可以检查这个线程来设置this conf at user level。 10ms是不是太小了?
-
嗨@Nimesh,我将连接设置为10ms的原因是因为我需要强制超时来复制错误,这在生产中不是这样的。但我想知道为什么没有显示超时错误。相反,我得到了 0 行的成功结果。
标签: c# postgresql oledb