惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

T
The Blog of Author Tim Ferriss
Hugging Face - Blog
Hugging Face - Blog
F
Fortinet All Blogs
B
Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Microsoft Security Blog
Microsoft Security Blog
Blog — PlanetScale
Blog — PlanetScale
月光博客
月光博客
腾讯CDC
小众软件
小众软件
G
Google Developers Blog
V
Visual Studio Blog
罗磊的独立博客
GbyAI
GbyAI
V
V2EX
大猫的无限游戏
大猫的无限游戏
H
Help Net Security
L
LangChain Blog
Engineering at Meta
Engineering at Meta
量子位
The GitHub Blog
The GitHub Blog
博客园 - 司徒正美
WordPress大学
WordPress大学
B
Blog RSS Feed

博客园 - xpengfee

【转】Quartz.NET 【转】阿里巴巴分布式服务框架 Dubbo 团队成员梁飞专访 【转】关于RabbitMQ 【转】windows下nginx+mono+fastCGI部署asp.net网站 【转】玩玩负载均衡---在window与linux下配置nginx 【转】亿级Web系统搭建——单机到分布式集群 【转】集群和负载均衡的概念 【转】SQL Server 2008 新数据类型 Dokuwiki 【转】反向AJAX 【转】Asp.net MVC Comet推送 【转】Comet:基于 HTTP 长连接的“服务器推”技术 【转】WEB前端调优 【转】jquery 注册事件的方法 【转】Google Chrome浏览器调试 【转】ASP.NET MVC 4 RC的JS/CSS打包压缩功能 VS妙用--自动创建文件注释头 Post流提交、接收 原型设计工具Axure RP分享
【转】SQLServer连接字符串配置:MultipleActiveResultSets
xpengfee · 2015-04-03 · via 博客园 - xpengfee

ADO.NET 1.x 利用SqlDataReader读取数据,针对每个结果集需要一个独立的连接。当然,你还必须管理这些连接并且要付出相应的内存和潜在的应用程序中的高度拥挤的瓶颈代价-特别是在数据集中的Web应用程序中。

      ADO.NET 2.的一个新特征多数据结果集(Multiple Active Result Sets,简称MARS)-它允许在单个连接上执行多重的数据库查询或存储过程。这样的结果是,你能够在单个连接上得到和管理多个、仅向前引用的、只读的结果集。目前实现这个功能的数据库只有Sql Server 2005。所以当我们针对Sql Sever 2005的时候,需要重新审视DataReader对象的使用。使用SqlServer 2005,可以在一个Command对象上同时打开多个DataReader,节约数据库联接所耗费的服务器资源,在实际开发中普遍存在的一种典型的从数据库中读写数据的情形是,你可以使用多重连接而现在只用一个连接就足够了。例如,如果你有一些来自于几个表中的数据-它们不能被联结到一个查询中,那么你就会有多重的连接-每个连接都有一个与之相关连的命令用于读取数据。同样,如果你正在向一个表写数据,那么你需要另外一个连接或连接集合-如果有多个表要被更新的话。

例如下面的代码

               //MultipleActiveResultSets=true打开联接

              string connstr = "server=(local);database=northwind;integrated security=true;MultipleActiveResultSets=true"; 

              SqlConnection conn = new SqlConnection(connstr);
            conn.Open();
            SqlCommand cmd1 = new SqlCommand("select * from customers", conn);
            SqlCommand cmd2 = new SqlCommand("select * from orders", conn);
            SqlDataReader rdr1 = cmd1.ExecuteReader();
           // next statement causes an error prior to SQL Server 2005
            SqlDataReader rdr2 = cmd2.ExecuteReader();
           // now you can reader from rdr1 and rdr2 at the same time.

              conn.Close();

原文链接:http://www.cnblogs.com/RobotH/archive/2007/08/22/865942.html