问题
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:
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.
来源:https://stackoverflow.com/questions/32999452/npgsql-one-connection-multiple-commands