国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學(xué)院 > 開發(fā)設(shè)計(jì) > 正文

Ado.net快馬加鞭

2019-11-18 16:33:04
字體:
供稿:網(wǎng)友

當(dāng)然首先是使用鏈接池了~~
連接池
Connection Timeout--嘗試連接數(shù)據(jù)存儲(chǔ)區(qū)時(shí)的等待時(shí)間默認(rèn)是15秒
Min Pool Size-連接池的最小容量
Max Pool Size-連接池最大容量默認(rèn)是100
Pooling 默認(rèn)是true則請(qǐng)求從連接池返回一個(gè)新的連接,沒有澤創(chuàng)建

Connection Reset表示在從連接池中刪除數(shù)據(jù)庫連接時(shí),將會(huì)重置該連接,默認(rèn)是true,如果設(shè)置成false則在創(chuàng)建連接時(shí)往返服務(wù)器的次數(shù)會(huì)更少但是不更新連接狀態(tài)

如果出了毛病就~~SqlConnection.ClearAllPools();//清除連接池
------然后是重頭戲~~自然是使用異步咯
1首先在連接字符串中設(shè)置一個(gè) async=true
-------理論就這么多了~~看段代碼爽爽把

 


31041條紀(jì)錄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();
    }
}
- -上面的只是小事伸手~~來個(gè)速度更快的


    //最強(qiáng)大的wait調(diào)用,只是把System.Threading.WaitHandle.WaitAll換成,System.Threading.WaitHandle.WaitAny因?yàn)镾ystem.Threading.WaitHandle.WaitAny
    //可以在某一格進(jìn)程結(jié)束后得到處理,修改try部分--注意看
    protected void Button4_Click(object sender, EventArgs e)
    {
        DateTime old = DateTime.Now;
        //實(shí)際上就是在第一個(gè)結(jié)果集是檢索的源,第二個(gè)結(jié)果集實(shí)際上只要查詢第一個(gè)結(jié)果集里面有的字段,不會(huì)在數(shù)據(jù)庫中查尋,而是用第一個(gè)結(jié)果集
        SqlConnection DBCon = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionStringInfo"].ConnectionString);
        SqlCommand Table_1Command = new SqlCommand("select  * from Table_2 where Id>4000001", DBCon);//---這里執(zhí)行查詢后
        SqlCommand MMCommand = new SqlCommand("select Title ,Content from MM,Table_2 where MM.ID=Table_2.Id", DBCon);//Table_2.Id其實(shí)是上面的Table_2地一列

        Table_1Command.CommandType = CommandType.Text;
        MMCommand.CommandType = CommandType.Text;

        SqlDataReader Table_1DataReader;
        SqlDataReader MMDataReader;

        IAsyncResult Table_1AsyncResult;
        IAsyncResult MMAsyncResult;

        System.Threading.WaitHandle[] WHandles = new System.Threading.WaitHandle[2];

        //封裝等待對(duì)共享資源的獨(dú)占訪問的操作系統(tǒng)特定的對(duì)象。
        System.Threading.WaitHandle Table_1Whandle;
        System.Threading.WaitHandle MMWhandle;

        try
        {

            DBCon.Open();
            Table_1AsyncResult = Table_1Command.BeginExecuteReader();
            MMAsyncResult = MMCommand.BeginExecuteReader();

            Table_1Whandle = Table_1AsyncResult.AsyncWaitHandle;
            MMWhandle = MMAsyncResult.AsyncWaitHandle;

            WHandles[0] = Table_1Whandle;
            WHandles[1] = MMWhandle;

            System.Threading.WaitHandle.WaitAny(WHandles);

 

 

            for (int index = 0; index < 2; index++)
            {
                //--------返回完成執(zhí)行等待句柄索引該數(shù)據(jù)在WHandles索引里面的某個(gè)
                int whindex = System.Threading.WaitHandle.WaitAny(WHandles);
                switch (whindex)
                {
                    //注意這里必須和上面裝入WHandles集合的索引一樣
                    case 0:
                        Table_1DataReader = Table_1Command.EndExecuteReader(Table_1AsyncResult);
                        GridView1.DataSource = Table_1DataReader;
                        GridView1.DataBind();
                        break;
                    case 1:

                        MMDataReader = MMCommand.EndExecuteReader(MMAsyncResult);
                        GridView2.DataSource = MMDataReader;
                        GridView2.DataBind();

                        break;

                }

            }

 

        }
        catch (System.Exception)
        {

        }
        finally
        {
            DBCon.Close();
        }

 

        TimeSpan not = DateTime.Now - old;
        Label1.Text = not.Seconds.ToString();
    }
~~上面的可是高級(jí)應(yīng)用--不過在怎么提速安全第一
首先要設(shè)置三臺(tái)服務(wù)器~~或者是三個(gè)sqlserver實(shí)例咯

 

主要服務(wù)器為.
景象服務(wù)器為./Partner
觀察者服務(wù)器為./Witness

然后再連接字符串中設(shè)置 FailOver Parter="./Partner"即可

--當(dāng)往主服務(wù)器中插入數(shù)據(jù)的時(shí)候竟象服務(wù)器也會(huì)插入數(shù)據(jù),如果主服務(wù)器停止工作則景象服務(wù)器被觀察者服務(wù)器設(shè)置為主服務(wù)器


發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 富顺县| 满洲里市| 五台县| 永城市| 融水| 湟中县| 吉林省| 峨眉山市| 繁峙县| 霍山县| 汉沽区| 唐河县| 新蔡县| 中江县| 六盘水市| 商城县| 屯昌县| 明光市| 鄂托克前旗| 五寨县| 远安县| 门头沟区| 闵行区| 陕西省| 尚志市| 双桥区| 长兴县| 内江市| 宁海县| 合水县| 娱乐| 延庆县| 武夷山市| 德格县| 罗山县| 侯马市| 灌南县| 西和县| 灵寿县| 梁山县| 永城市|