[Asp.net] unknown questions!

Source: Internet
Author: User

Here we will discuss the data underlying layer in the three (Multi) layer structure!

Generally, you are writingProgramAllCodeIt is written as a class or function. The same is true for database write operations. This is a problem!

In the database connection class, if an instance is a class or a method is called, the connection open () will be opened or the instance will be restarted once. Sometimes for a page, you only need to open () once, but open () multiple times in the code. In this way, resources will not be wasted?

For example:

On a page with a DataGrid or datalist, you will write the. datasource and. databind () of the DataGrid or datalist as a function, right. However, datasource will certainly call a class method to read data. To call this method, you must instance a class, that is, the connection must be open () once. This problem arises.

Let us assume that we must first update the data (insert) on the page and then read the data (select) in the database ). In this way, the connection will be open () and close () twice or more.

Of course, we can write open () and close () as public functions and then operate them externally. But this adds the annoyance of the Code.

I wonder if you have such a problem. I personally have read the underlying layers of the layer-3 structure written by others! One method is open () and close () once. If you want to call several methods on a page, open () will be called several times. Isn't it a waste of resources?

Official Ms statement: the connection to the database should be closed as quickly as possible

HoweverIf only several SQL operations on a page are required, open () and close () are required several times. In comparison, is it faster than open () and close?

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.