Datareader. Close timeout exception caused by Big Data

Source: Internet
Author: User

A company's data grabbing program has a large amount of data. The idatareader's read method is used for data processing,
During the test, I want to run part of the data and jump out of the loop, that is, break; then close datareader, but execute datareader. when the close () method is used, the "timeout exception" error occurs. Check the descriptions of the close method in msdn as follows:

When you use sqldatareader to use the associated sqlconnection for any other purpose, you must explicitly call the close method.

The close method fills in the output parameter values, return values, and recordsaffected, increasing the time used to close sqldatareader for processing large or complex queries. If the return value is not important to the number of records affected by the query, you can call the Cancel Method of the associated sqlcommand object before calling the close method to reduce the time required to disable sqldatareader.

The cancel method that previously executed the command can solve this problem.

 

1 Public void testdatareader () 2 {3 using (idatareader reader = cmd. executereader (commandbehavior. closeconnection) 4 {5 try 6 {7 while (reader. read () 8 {9 // process data 10 // break; 11 // process data 12} 13} 14 finally15 {16 cmd. cancel (); 17 reader. close (); 18} 19} 20}
Related Article

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.