问题
Using v3.0.3 of Npgsql and my app works fine on my PC.
When I run it on my RaspPI2 with Mono, I get an error in the title. After getting the error the first time, I put a lock() around the section. After getting the error again, I add "Pooling=false" to the connection string, thinking perhaps that another part of the app was actively consuming data.
This application uses the MySQL connector just fine. The code below, should be the first instance of where I access my Postgres db.
(updated) connection string:
public const string connectionString = "server=192.168.32.45;user id=******;password=*****;database=******;Pooling=false";
logging info:
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:
Exception info:
[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
The code:
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())
{
....
}
}
}
}
I tried updating the App.Config as mentioned here: (Stackoverflow) how to deploy npgsql on Raspberry pi 2 (Mono 4 + ARM proc)? and still same issue.
来源:https://stackoverflow.com/questions/33131285/npgsql-on-mono-an-operation-is-already-in-progress