Npgsql: One connection, multiple commands

戏子无情 提交于 2020-03-22 06:11:30

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!