使用組件封裝數(shù)據(jù)庫設(shè)置(一)
發(fā)表時間:2024-01-17 來源:明輝站整理相關(guān)軟件相關(guān)文章人氣:
[摘要]其實,大家在書寫asp程序時,最擔(dān)心的可能就是數(shù)據(jù)庫的連接信息,會被一些人看到,進(jìn)行一些破壞。下面我們用vb6.0來做一個動態(tài)鏈接庫(.dll)來隱藏數(shù)據(jù)庫的連接信息。 啟動vb6.0,新建-->Active dll工程。單擊"工程"-->引用,選擇"...
其實,大家在書寫asp程序時,最擔(dān)心的可能就是數(shù)據(jù)庫的連接信息,會被一些人看到,進(jìn)行一些破壞。下面我們用vb6.0來做一個動態(tài)鏈接庫(.dll)來隱藏數(shù)據(jù)庫的連接信息。
啟動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
'以上語句是必須的。
'定義兩個公有函數(shù)
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文件.當(dāng)然了,你也可以在其它文件中使用。
set dcss=server.CreateObject("yygwy.dcss")
oconn=dcss.datasource()
application("strconn")=oconn
在其它的頁面中如下調(diào)用即可:
set objConn = Server.CreateObject("ADODB.Connection")
objConn.Open application("strconn")