Use Application and Session to optimize Asp database connection

Source: Internet
Author: User
.... For the connection management of databases in Asp development, the common solution is to call a conn. the asp page defines the relevant variables in it, and then establishes the corresponding Connection based on different database types. This page will be called in other places where the database needs to be connected in the future, then proceed accordingly!
In my recent research, I found that this method is not optimal. For a slightly larger system Forum, if the connection time is exceeded during each page call, I need to re-establish the connection to the database. My initial idea is: in the conn. in the asp page, an open Connection is assigned to the Application for saving, and then the Application Connection is assigned to the Session for each new Connection user; in this way, each user can establish only one Connection, which will be helpful for speed improvement and database load, especially when there are many users. (Asp development is only available recently because I want to build an information platform. I am sorry to say this !)
Attach my conn. asp code:
<%
XzcInforCookies = "xzcInfor"
On error resume next
If g_dataBaseSort = "A" Then
G_connStr = "DBQ =" & server. mapPath ("" & g_dataPath & "" & g_DBMasterName & "") & "; DRIVER = {Microsoft Access Driver (*. mdb )};"
SqlNowString = "Now ()"
SqlChar = "'"
Connstr = "Provider = Microsoft. Jet. OLEDB.4.0; Data Source =" & Server. MapPath ("" & g_dataPath & "" & g_DBMasterName &"")
Else
SqlLocalName = "192. 1. *. *" 'connection IP address
SqlUsername = "*****" 'user name
SqlPassword = "****" 'user password
SqlDatabaseName = "***" 'database name
G_connStr = "Provider = Sqloledb; User ID =" & SqlUsername & "; Password =" & SqlPassword & "; Initial Catalog =" & SqlDatabaseName &"; data Source = "& SqlLocalName &";"

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.