其實,大家在書寫asp程式時,最擔心的可能就是資料庫的連線訊息,會被一些人看到,進行一些破壞。下面我們用vb6.0來做一個動態連結函式庫(.dll)來隱藏資料庫的連線資訊。
啟動vb6.0,新建-->Active dll工程。點選"工程"-->引用,選擇"microsoft active server pages object library"
和"microsoft activeX data objects 2.1 library"兩項。將類別模組的名稱改為dcss.將工程的名稱改為yygwy.保存工程文件yygwy.vbp和類別文件dcss.cls。
在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 onendpage()
Set myscriptingcontext = Nothing
Set myapplication = Nothing
Set myrequest = Nothing
Set myresponse = Nothing
Set myserver = Nothing
Set mysession = Nothing
End Sub
'以上語句是必須的。
'定義兩個公有函數
Public Function datasource() As Variant
datasource = "driver={sql server};server=yang;uid=sa;pwd=; database=dcss"
End Function
編譯產生dcss.dll檔。註冊regsvr32 路徑dcss.dll。
用visual interdev打開global.asa檔.當然了,你也可以在其它檔中使用。
set dcss=server.CreateObject("yygwy.dcss")
oconn=dcss.datasource()
application("strconn")=oconn
在其它的頁面中如下調用即可:
set objConn = Server.CreateObject("ADODB.Connection")
objConn.Open application("strconn")