5

is it possible to execute multiple NpgslqCommands against one connection? I mean like:

conn.Open();
ExecuteCommandA(conn);
ExecuteCommandB(conn);
ExecuteCommandC(conn);
conn.Close();

I believe, it should be possible, but is there any issue here? If there is a batch of commands to be executed, that could take a longer time, there is a chance the connection could be lost or some other error can happen.

So it should be tested, right? Also can a command bring the connection into some kind error state?

Thanks for answers...

/IP/

1
  • 1
    Yes it is possible, as you can very quickly test. Errors can always happen. Commands won't break connections in any way. Oct 7, 2015 at 18:12

1 Answer 1

6

As said above, there is no issue with executing multiple commands serially on the same connection. Connections can always break (e.g. network cut), this has nothing to do with how many commands you run.

If you want to execute the commands in parallel, you need to open multiple connections and execute one command on each one. However, be careful of touching the same data across the different commands, and be aware of the added overhead of multiple connections on your PostgreSQL.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.