Npgsql:一个连接,多个命令 [英] Npgsql: One connection, multiple commands

查看:65
本文介绍了Npgsql:一个连接,多个命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以针对一个连接执行多个 NpgslqCommands?我的意思是:

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?

感谢您的回答...

/IP/

推荐答案

如上所述,在同一个连接上串行执行多个命令没有问题.连接总是会中断(例如网络中断),这与您运行的命令数量无关.

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.

如果你想并行执行命令,你需要打开多个连接并在每个连接上执行一个命令.但是,请注意跨不同命令接触相同数据,并注意 PostgreSQL 上多个连接的额外开销.

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.

这篇关于Npgsql:一个连接,多个命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆