使用Npgsql的v3.0.3和我的应用程序在我的电脑上正常工作。
当我使用Mono在我的RaspPI2上运行它时,标题中出现错误。在第一次收到错误后,我在该部分周围放置了一个lock()。在再次收到错误后,我将“Pooling = false”添加到连接字符串中,可能认为应用程序的另一部分正在积极地使用数据。
这个应用程序使用MySQL连接器就好了。下面的代码应该是我访问Postgres数据库的第一个实例。
(更新)连接字符串:
public const string connectionString = "server=192.168.32.45;user id=******;password=*****;database=******;Pooling=false";
记录信息:
Level: Debug, Id: 0, MSG: Opening connnection, Ex:
Level: Trace, Id: 0, MSG: Attempting to connect to 192.168.32.45, Ex:
Level: Debug, Id: 0, MSG: Connected to 192.168.32.45:5432, Ex:
Level: Debug, Id: 0, MSG: Authenticating..., Ex:
Level: Trace, Id: 0, MSG: Received AuthenticationRequest of type AuthenticationMD5Password, Ex:
Level: Trace, Id: 0, MSG: Received AuthenticationRequest of type AuthenticationOk, Ex:
Level: Debug, Id: 0, MSG: ExecuteReader with CommandBehavior=SequentialAccess, Ex:
Level: Debug, Id: 14849, MSG: ExecuteReader, Ex:
Level: Trace, Id: 14849, MSG: Break connector, Ex:
Level: Trace, Id: 14849, MSG: Cleanup connector, Ex:
Level: Trace, Id: 14849, MSG: Really closing connection, Ex:
Level: Debug, Id: 14849, MSG: Close connector, Ex:
异常信息:
[ERROR] FATAL UNHANDLED EXCEPTION: System.InvalidOperationException: An operation is already in progress.
at Npgsql.NpgsqlConnector.StartUserAction (ConnectorState newState) [0x00000] in <filename unknown>:0
at Npgsql.NpgsqlCommand.ExecuteDbDataReaderInternal (CommandBehavior behavior) [0x00000] in <filename unknown>:0
at Npgsql.NpgsqlCommand.ExecuteDbDataReader (CommandBehavior behavior) [0x00000] in <filename unknown>:0
at System.Data.Common.DbCommand.ExecuteReader (CommandBehavior behavior) [0x00000] in <filename unknown>:0
at Npgsql.NpgsqlCommand.ExecuteReader (CommandBehavior behavior) [0x00000] in <filename unknown>:0
at (wrapper remoting-invoke-with-check) Npgsql.NpgsqlCommand:ExecuteReader (System.Data.CommandBehavior)
at Npgsql.TypeHandlerRegistry.LoadBackendTypes (Npgsql.NpgsqlConnector connector) [0x00000] in <filename unknown>:0
at Npgsql.TypeHandlerRegistry.Setup (Npgsql.NpgsqlConnector connector) [0x00000] in <filename unknown>:0
at Npgsql.NpgsqlConnector.Open () [0x00000] in <filename unknown>:0
代码:
using (var con = new NpgsqlConnection(AppSharedObject.connectionString))
using (var cmd = con.CreateCommand())
{
con.Open();
cmd.CommandTimeout = 120;
cmd.CommandText = sql;
using (var rdr = cmd.ExecuteReader())
{
while (rdr.Read())
{
....
}
}
}
}
我尝试更新此处提到的App.Config :( Stackoverflow)how to deploy npgsql on Raspberry pi 2 (Mono 4 + ARM proc)?但问题仍然存在。