C# 单声道上的Npgsql:“;操作已在进行中。”;

C# 单声道上的Npgsql:“;操作已在进行中。”;,c#,mono,npgsql,C#,Mono,Npgsql,使用Npgsql的v3.0.3和我的应用程序在我的PC上运行良好 当我用Mono在我的RaspPI2上运行它时,标题中出现了一个错误。在第一次得到错误后,我在该部分周围放置了一个锁()。再次出现错误后,我将“Pooling=false”添加到连接字符串中,认为应用程序的另一部分可能正在积极地消耗数据 这个应用程序很好地使用了MySQL连接器。下面的代码应该是我访问Postgres db的第一个实例 (更新)连接字符串: public const string connectionString =

使用Npgsql的v3.0.3和我的应用程序在我的PC上运行良好

当我用Mono在我的RaspPI2上运行它时,标题中出现了一个错误。在第一次得到错误后,我在该部分周围放置了一个锁()。再次出现错误后,我将“Pooling=false”添加到连接字符串中,认为应用程序的另一部分可能正在积极地消耗数据

这个应用程序很好地使用了MySQL连接器。下面的代码应该是我访问Postgres db的第一个实例

(更新)连接字符串:

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

我试着更新这里提到的App.Config:(Stackoverflow),但仍然是相同的问题。

查看npgsql和mono代码。在低端机器上可能会遇到此异常。仍在试图确定这是mono还是npgsql错误。我所做的快速修复是在StartUserAction内用大于0毫秒的等待时间重建npgsql。我在npgsql 3.0.4中也有同样的问题,我也有类似的问题。通过在作用域末尾执行手动rdr.Close()来解决此问题。(当使用C++的PGSQL时,这不是必需的,因为它在范围结束时由析构函数自动调用)。
  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())
               {
                  .... 
               }
          }
      }
  }