application|session| Data | database | optimization .... For the database connection management in ASP development, At present, the general processing method is to call a conn.asp page, in which the relevant variables are defined, and then according to the different database types, to establish a good corresponding connection, then the other need to join the database to call the page, and then the corresponding processing!
In my recent research, I have found that this method is not optimal, for a slightly larger system forum, in the case of each page call if more than the connection time, you need to re-establish the connection to the database , my initial idea is: in the conn.asp page, assign an open connection to application, and then assign the application connection to the session for each new connected user, thus ensuring that each user builds only one connecti On, there is a certain amount of help for speed increases and database loads, especially when there are more users. (recently because to do an information platform, to contact the development of ASP, it is inevitable to say wrong, please forgive me!) )
Enclosed is my conn.asp code:
<%
Xzcinforcookies = "Xzcinfor"
On Error Resume Next
if g_databasesort = "A" Then
g_connstr = "dbq=" & Server. MapPath ("&g_dataPath&" \ "&g_DBMasterName&") & ";D river={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.*.*" ' Connect IP
SqlUsername = ' * * * ' ' username
SqlPassword = ' * * * ' ' user password
sqldatabasename= "* * *" ' database name
G_connstr = "PROVIDER=SQLOLEDB; User id= "& Sqlusername &"; Password= "& SQLPassword &"; Initial Catalog = "& Sqldatabasename &"; Data source= "& Sqllocalname &";
sqlnowstring = "GetDate ()"
SqlChar = ""
ver = "4.10 SQL"
End If
'========================================================
'--Use application ' s connection for better performance
'--------------------------------------------------------
If IsObject (Application (xzcinforcookies & "conn") = False Then
Set g_conn = Server. CreateObject ("Adodb.connection")
G_conn.commandtimeout = 60 ' in seconds
G_conn. Open G_connstr
If G_conn. Errors.count>0 Then ' error handling (including connection errors and Oracle database errors)
For I=0 to G_conn. Errors.count-1
Temperr=replace (replace (g_conn. Errors (i). Description,vbcrlf, ""), vbcr, ""), vblf, "")
Response.Write "<script language= ' VBScript ' >" + vbCrLf
Response.Write "MsgBox" has a database connection error, please contact the administrator. Error prompts as follows: "&vbcrlf&vbcrlf&" "&tempErr&" ", vbOKOnly," "Error Message" "" + vbCrLf
Response.Write "</script>"
Next
Response.End
End If
Application.Lock
Set Application (Xzcinforcookies & "conn") = G_conn
Application.UnLock
End If
'=========================================
'--Every user use own session connection
'-----------------------------------------
If session (Session.SessionID & "conn") = "" Then
Set session (Session.SessionID & "conn") = Application (Xzcinforcookies & "Conn")
End If
Set G_conn = Session (Session.SessionID & "Conn")
%>