In fact, what everyone is most worried about when writing an ASP program is that the database connection information will be seen by some people and cause some damage. Next we use vb6.0 to make a dynamic link library (.dll) to hide the database connection information.
Start vb6.0, create new --> Active dll project. Click "Project"-->References and select "Microsoft Active Server Pages Object Library"
and "microsoft activeX data objects 2.1 library" two items. Change the name of the class module to dcss. Change the name of the project to yygwy. Save the project file yygwy.vbp and the class file dcss.cls.
Write in dcss.cls:
Private myscriptingcontext As ScriptingContext
Private myapplication As Application
Private myrequest As Request
Private myresponse As Response
Private myserver As Server
Private session As Session
Public Sub onstartpage(passedscriptingcontext As ScriptingContext)
Set myscriptingcontext = passedscriptingcontext
Set myapplication = myscriptingcontext.Application
Set myrequest = myscriptingcontext.Request
Set myresponse = myscriptingcontext.Response
Set myserver = myscriptingcontext.Server
Set mysession = myscriptingcontext.Session
End Sub
Public Sub onendpage()
Set myscriptingcontext = Nothing
Set myapplication = Nothing
Set myrequest = Nothing
Set myresponse = Nothing
Set myserver = Nothing
Set mysession = Nothing
End Sub
'The above statement is required.
'Define two public functions
Public Function rsresult(strsql As String) As Recordset
Dim mycnn As Connection
Dim myset As Recordset
Dim strconnstring As String
'strconnstring = "provider=sqloledb.1;
password=;" & "user id=sa;" & "initial catalog=vlog;" & "data source=hpe60;
connect timeout=15"
strconnstring = "driver={sql server};server=yang;uid=sa;pwd=;
database=dcss"
'mycnn.ConnectionString = strconnstring
mycnn.Open strconnstring
myset.ActiveConnection = mycnn
myset.Open strsql, mycnn, 3, adCmdText
Set rsresult = myset
End Function
Public Function datasource() As Variant
datasource = "driver={sql server};server=yang;uid=sa;pwd=; database=dcss"
End Function
compiles and generates the dcss.dll file. Register regsvr32 pathdcss.dll.
Open the global.asa file with visual interdev. Of course, you can also use it in other files.
set dcss=server.CreateObject("yygwy.dcss")
oconn=dcss.datasource()
application("strconn")=oconn
can be called as follows in other pages:
set objConn = Server.CreateObject("ADODB.Connection")
objConn.Open application("strconn")