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?