我有一些 C#,我在其中创建连接上的读取器 (ExecuteReader
),然后针对该读取器中的每一行执行另一个命令(使用 ExecuteNonQuery
)。在这种情况下,我在连接上使用 MultipleActiveResultSets=True
还是使用多个连接更好?
最佳答案
Multiple Active Result Sets (MARS) 是专门为此类操作添加的,因此您不必同时打开两个连接即可从 SqlDataReader 读取数据并执行其他批处理。
MARS 与 SQL Server 2005 及更高版本兼容。引用自 MSDN 文档:
Before the introduction of Multiple Active Result Sets (MARS), developers had to use either multiple connections or server-side cursors to solve certain scenarios.
有关详细信息,请参阅:
读取和更新数据的工作示例:
MSDN Library - Manipulating Data (MARS) scroll down to 'Reading and Updating Data with MARS'
关于c# - MultipleActiveResultSets=True 或多个连接?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/510899/