Asynchronous query of ado.net database queries

Source: Internet
Author: User

Today, we make a function to query tables with a certain amount of data. However, there are many related effects in the footer. In order. Poor user experience. Therefore, asynchronous queries are considered. It is to do other threads during Operation query. I was thinking about multithreading. But because it is a web program. Therefore, give up.

Considering that the asynchronous query function of ado.net has never been used, let's make a demo to check the performance.

Static void Main (string [] args)
{

String constr = @ "Data Source = ***. ***. ***. * **; uid = *****; pwd = *****; database = *****; Asynchronous Processing = true ";
Using (SqlConnection con = new SqlConnection (constr ))
{
Using (SqlCommand cmd = new SqlCommand ("waitfor delay '00: 00: 10' select top 50 * from TEshow", con) // delay of 10 seconds to test the effect
{
Con. Open ();
Console. WriteLine ("sssssss ");
IAsyncResult iay = cmd. BeginExecuteReader ();
Console. WriteLine ("bbbbbbb ");
SqlDataReader dr = cmd. EndExecuteReader (iay );
While (dr. Read ())
{
String msg = string. format ("the first number is: {0}, the second number is: {1}", dr [0]. toString (), dr [1]. toString ());
Console. WriteLine (msg );
}

Console. ReadLine ();
}
}
}

It feels okay.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.