For some reason, I get the code with an error: System.InvalidOperationException: An operation is already in progress.
I read a little and came to the conclusion that the problem may be that I do not complete the transaction (I do not execute commits). The question is. Is there a point in them, and at what point do I need to commit them? Do I need to start a transaction before each request or how?
public void PGConnect () {
// UserData [] uds; List<UserData> uds = new List<UserData>(); UserData ud; List<string> 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); } //NpgsqlTransaction tr = conn.BeginTransaction(); // Где-то в этом блоке ошибка 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 -> 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); } } // Конец блока где ошибка. Console.ReadKey(); NpgsqlCommand command = new NpgsqlCommand("SELECT city, state FROM cities", conn); try { NpgsqlDataReader dr = command.ExecuteReader(); 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(); }