我正在尝试使用.Net 4.5,Npgsql 3.1.6 NuGet包的Postgres Plus 9.5。 我已经阅读了有关此错误的内容,但我不明白为什么会得到它。一切都处理好了。这是代码:
public override DataTable getActListData(int FunkNr)
{
using (var cmd = new NpgsqlCommand())
{
cmd.CommandText = npgsqlCommand3.CommandText;
cmd.Connection = this.npgsqlConnection;
cmd.Parameters.Add(new Npgsql.NpgsqlParameter("ANWENDUNG", NpgsqlTypes.NpgsqlDbType.Numeric));
cmd.Parameters.Add(new Npgsql.NpgsqlParameter("XFUNKNR", NpgsqlTypes.NpgsqlDbType.Numeric));
using (var da = new NpgsqlDataAdapter(npgsqlCommand3))
{
var tab = new DataTable();
da.SelectCommand.Parameters["ANWENDUNG"].Value = getAnwendung();
da.SelectCommand.Parameters["XFUNKNR"].Value = FunkNr;
da.Fill(tab); // Here is the error on the 5th call
return tab;
}
}
}
这个问题是来自Npgsql还是来自Postgres?
其他一些问题:
我在这里读过,懒加载是不可能的,但我不明白是因为Npgsql还是来自Postgres?
在Postgres中是否可以打开多个游标并在同一连接中按需阅读?
编辑:更改了代码:
using (var npgsqlConnection = new NpgsqlConnection())
{
ConnectionString = string.Format(DataClientFactory.DataBaseConnectString, DB, User, PW);
npgsqlConnection.ConnectionString = ConnectionString;
npgsqlConnection.Open();
....
the code above here
....
}
同一个电话中出现同样的错误。错误:
System.InvalidOperationException occurred
HResult=-2146233079
Message=An operation is already in progress.
Source=Npgsql
StackTrace:
bei Npgsql.NpgsqlConnector.StartUserAction(ConnectorState newState)
InnerException:
答案 0 :(得分:0)
如果您发布的代码段同时在同一个连接上运行,则说明您的问题 - Npgsql连接不是线程安全的,并且无法打开多个读取器同时(MARS)。