【www.gdgbn.com--页面特效】

这是一段正常的程序,这段程序放在一个页面里,无论你怎么刷或者多少人同时请求这个页面,待请求处理结束后,通过sp_who查看到的,还是那一个。知道这为什么叫正常的程序了吧,符合正常推理

using (sqldatareader reader = maticsoft.dbutility.dbhelpersql.executereader("select top 1 * from protuct order by id desc"))
           {
               while (reader.read())
               {
                   response.write(reader["name"].tostring());
               }
           }
using (sqldatareader reader2 = maticsoft.dbutility.dbhelpersql.executereader("select top 1 * from users order by userid desc"))
           {
               while (reader2.read())
               {
                   response.write(reader2["username"].tostring());
               }
           }

看一下我们有些朋友会经常用的连接数据代码

data source=.;initial catalog=test;persist security info=true;user id=testuser;password=123456;min pool size=10;max pool size=150;connection lifetime=10

min pool size=10;max pool size=150;connection lifetime=10

数据库教程连接池 了,默认是启用的,以上的属性就是配置这个连接池的。这也就意味着,当你的页面发送数据库请求的时候,不一定就非要创建数据库连接,而可能是从已存在连接池里,激活一个的连接来处理你的请求的;同样,当你代码中调用close显式关闭数据库连接的时候,也不一定就是真的关闭数据库连接了,如果当前连接池中没有满足min pool size要求的连接时,它只是返回到连接池,等待下一个命令来激活它


sp_who "testusers"    // testusers是你建立连接时指定的用户名

看看连接数,现在明白了吧。

本文来源:http://www.gdgbn.com/wangyetexiao/28894/