免费邮箱 |加入收藏 | 会员中心 | 我要投稿 | RSS
您当前的位置:首页 > .NET专区 > ASP.NET应用

Ado.net快马加鞭

时间:2011-05-21 10:47:30  来源:站内  作者:潘春会

当然首先是使用链接池了~~
连接池
Connection Timeout--尝试连接数据存储区时的等待时间默认是15秒
Min Pool Size-连接池的最小容量
Max Pool Size-连接池最大容量默认是100
Pooling 默认是true则请求从连接池返回一个新的连接,没有泽创建

Connection Reset表示在从连接池中删除数据库连接时,将会重置该连接,默认是true,如果设置成false则在创建连接时往返服务器的次数会更少但是不更新连接状态

如果出了毛病就~~SqlConnection.ClearAllPools();//清除连接池
------然后是重头戏~~自然是使用异步咯
1首先在连接字符串中设置一个 async=true
-------理论就这么多了~~看段代码爽爽把

 


31041条纪录4秒


using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class Default5 : System.Web.UI.Page
{
    PRotected void Page_Load(object sender, EventArgs e)
    {


    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        DateTime old = DateTime.Now;

        SqlConnection DbCon;
        SqlCommand Command = new SqlCommand();
        SqlDataReader OrdersReader;
        IAsyncResult AsyncResult;//异步


        DbCon = new SqlConnection();
        DbCon.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionStringInfo"].ConnectionString;
        Command.Connection = DbCon;


        Command.CommandText = "Select";
        Command.CommandType = CommandType.StoredProcedure;
        Command.Connection = DbCon;

        try
        {
            DbCon.Open();
            AsyncResult = Command.BeginExecuteReader();
            while (!AsyncResult.IsCompleted)//获取异步操作是否已完成的指示。
            {
                //由于异步操作必须阻止线程秒钟
                System.Threading.Thread.Sleep(10);

            }
            OrdersReader = Command.EndExecuteReader(AsyncResult);
            GridView1.DataSource = OrdersReader;
            GridView1.DataBind();
        }
        catch (System.Exception)
        {

        }
        TimeSpan not=DateTime.Now-old;
        Label1.Text = not.Seconds.ToString();
    }
}
- -上面的只是小事伸手~~来个速度更快的


    //最强大的wait调用,只是把System.Threading.WaitHandle.WaitAll换成,System.Threading.WaitHandle.WaitAny因为System.Threading.WaitHandle.WaitAny
    //可以在某一格进程结束后得到处理,修改try部分--注意看
    protected void Button4_Click(object sender, EventArgs e)
    {
        DateTime old = DateTime.Now;
        //实际上就是在第一个结果集是检索的源,第二个结果集实际上只要查询第一个结果集里面有的字段,不会在数据库中查寻,而是用第一个结果集
        SqlConnection DBCon = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionStringInfo"].ConnectionString);
        SqlCommand Table_1Command = new SqlCommand("select  * from Table_2 where Id>4000001", DBCon);//---这里执行查询后

来顶一下
返回首页
返回首页
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表
推荐资讯
如何找出DHCP地址池里未使用的IP地址
如何找出DHCP地址池里
国内常用的DNS列表
国内常用的DNS列表
Linux邮件服务器软件比较
Linux邮件服务器软件比
学用纯CSS打造可折叠树状菜单
学用纯CSS打造可折叠树
相关文章
栏目更新
栏目热门