In fact, everyone is writing an ASP program, the most worrying may be the connection information of the database, will be seen by some people, and some destruction. Below we use VB6.0 to make a dynamic link library (.dll) to hide the connection information of the database.
Start VB6.0, New-> Active DLL Project. Click "Project" -> Quote, select "Microsoft Active Server Pages Object Library"
And "Microsoft ActiveX Data Objects 2.1 Library". Change the name of the class module to DCSS. Change the name of the project to YYGWY. Save the project file yygwy.vbp and 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 mysession 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 OneendPage () SET myscriptingContext = Nothing set myapplication = Nothing set myrequest = Nothing set myresponse = nothing set myServer = Nothing set mySession = Nothing end SUB
'The above statement is necessary. '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 FunctionPublic Function datasource () As Variant datasource = "driver = {sql server}; server = yang; uid = sa; pwd =; database = dcss "End function
Compile the DCSS.DLL file. Register Regsvr32 path /dcss.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.dataasource () Application ("strconn") = Oconn
Call as follows in other pages: set objconn = server.createObject ("adodb.connection" Objconn.open Application ("strconn")