title: Why I am getting error: An operation is already in progress
body: <p>I am getting next error:</p>
  
  <blockquote>
    <p>System.InvalidOperationException: An operation is already in progress.</p>
  </blockquote>
  
  <p>I can't understand it's reason. If I comment block that start-end all work fine. If no I am betting error. Any ideas?</p>
  
  <pre><code>     public void PGConnect()
      {
          List&lt;UserData&gt; uds = new List&lt;UserData&gt;();
          UserData ud;
  
          List&lt;string&gt; dblist = GetListDBsList();
          if (dblist.Contains(config.PGdbName))
          {
              Console.WriteLine("Data Base exists: {0}", config.PGdbName);
          }
  
          else
          {
              Console.WriteLine("Data Base DO NOT exists: {0}", config.PGdbName);
              return;
          }
  
          NpgsqlConnection conn = new NpgsqlConnection("Server=127.0.0.1;Port=5432;User Id=" + config.PGLogin + ";" +
             "Password=" + config.PGPass + ";Database=" + config.PGdbName + ";");
  
          //select datname from pg_database;
  
          try
          {
              conn.Open();
  
              Console.WriteLine("PG Connected");
          }
  
          catch(SocketException e)
          {
              Console.WriteLine(e.Message);
  
          }
  
          //start
          string tablesListRequestSQL = @"SELECT table_name FROM information_schema.tables WHERE table_schema='public'";
          NpgsqlCommand commandGetDBTables = new NpgsqlCommand(tablesListRequestSQL, conn);
          NpgsqlDataReader drGetDBTables = commandGetDBTables.ExecuteReader();
          //tr.Commit();
          while (drGetDBTables.Read())
          {
              existsInDBTables.Add(drGetDBTables[0].ToString());
          }
  
          foreach (string table in requireTablesList) // 
          {
              if (!existsInDBTables.Contains(table)) // if element from requireTablesList do not found -&gt; DB have not simmilar Tables!
              {
                  notFoundedTables.Add(table);
              }
  
          }
  
          if (notFoundedTables.Count != 0) // if not empty
          {
              Console.WriteLine("Next tables are marked as reqired for Sync, but can't be found in DataBase: ");
  
              foreach (var table in notFoundedTables)
              {
                  Console.WriteLine(table);
              }
          }
          // end 
  
  
          Console.ReadKey();
  
  
           NpgsqlCommand command = new NpgsqlCommand("SELECT city, state FROM cities", conn);
  
  
          try
          {
  
              NpgsqlDataReader dr = command.ExecuteReader(); // VS show error here
              while (dr.Read())
              {
                 // UserData ud = new UserData();
                  ud.id = Int32.Parse(dr[0].ToString());
                  ud.guid = (dr[1].ToString());
                  ud.name = (dr[2].ToString());
                  ud.userblob = (byte[])dr[3];
                  uds.Add(ud);
                  //File.WriteAllBytes("outputimg.jpg", ud.userblob);
                  //Console.ReadKey();
  
              }
  
          }
  
          finally
          {
              conn.Close();
          }
  </code></pre>
  
  <hr>
  
  <p>Windows 7. VS2015. PG 9.5</p>
  
  <hr>
  
  <p>How it's look like:
  <a href="https://i.stack.imgur.com/PzkaF.png" rel="noreferrer"><img src="https://i.stack.imgur.com/PzkaF.png" alt="my picture looks like this"></a></p>
  
  <hr>
  
  <p>More pictures here:</p>
  
  <p><a href="http://img.ctrlv.in/img/16/04/20/5717882d0b968.png" rel="noreferrer">http://img.ctrlv.in/img/16/04/20/5717882d0b968.png</a></p>
  
  <p><a href="http://img.ctrlv.in/img/16/04/20/57179041abaa4.png" rel="noreferrer">http://img.ctrlv.in/img/16/04/20/57179041abaa4.png</a></p>
  
  <p><a href="http://img.ctrlv.in/img/16/04/20/571790825648f.png" rel="noreferrer">http://img.ctrlv.in/img/16/04/20/571790825648f.png</a></p>