MultipleActiveResultSets=True 还是多个连接? [英] MultipleActiveResultSets=True or multiple connections?

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

问题描述

我有一些 C#,在其中我在连接 (ExecuteReader) 上创建了一个阅读器,然后对该阅读器中的每一行执行另一个命令(使用 ExecuteNonQuery).在这种情况下,我在连接上使用 MultipleActiveResultSets=True 还是使用多个连接更好?

I have some C# in which I create a reader on a connection (ExecuteReader), then for every row in that reader, perform another command (with ExecuteNonQuery). In this case is it better that I use MultipleActiveResultSets=True on my connection or use multiple connections?

推荐答案

多活动结果集 (MARS) 是专门为此类操作添加的,因此您不必同时打开两个连接即可能够从 SqlDataReader 读取并执行额外的批处理.

Multiple Active Result Sets (MARS) was added specifically for this type of operation so that you don't have to have two connections open at the same time to be able to read from a SqlDataReader AND execute additional batches.

MARS 与 SQL Server 2005 及更高版本兼容.引用 MSDN 文档:

MARS is compatible with SQL Server 2005 and above. To quote from MSDN docs:

引入Multiple之前活动结果集 (MARS),开发人员必须使用多个连接或服务器端游标来解决某些场景.

Before the introduction of Multiple Active Result Sets (MARS), developers had to use either multiple connections or server-side cursors to solve certain scenarios.

有关更多信息,请参阅:

For more info see:

MSDN 库 - MARS 概述

读取和更新数据的工作示例:

Worked example reading and updating data:

MSDN 库 - 操作数据 (MARS) 向下滚动到使用MARS'读取和更新数据

MSDN Library - Manipulating Data (MARS) scroll down to 'Reading and Updating Data with MARS'

这篇关于MultipleActiveResultSets=True 还是多个连接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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