我打算将ASP的数据库连接字符串封装到DLL
以下是我的VB ActiveX DLL源代码
有调用ASP.DLL,ADO.DLL
Project:Mycom
class:Appliction
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 SubPublic Sub db_open()
Dim condbstring As String
Set condb = MyServer.CreateObject("ADODB.Connection")
condbstring = "Driver={SQL Server};Database=xxxx;server=localhost;uid=xxx;pwd=xxx"
condb.Open (condbstring)
End SubPublic Sub db_close()
condb.Close
End Sub有什么方法可以在外部调用condb
以下是我的VB ActiveX DLL源代码
有调用ASP.DLL,ADO.DLL
Project:Mycom
class:Appliction
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 SubPublic Sub db_open()
Dim condbstring As String
Set condb = MyServer.CreateObject("ADODB.Connection")
condbstring = "Driver={SQL Server};Database=xxxx;server=localhost;uid=xxx;pwd=xxx"
condb.Open (condbstring)
End SubPublic Sub db_close()
condb.Close
End Sub有什么方法可以在外部调用condb
Set ConDB=condb
End Property
其實可以這樣VB組件一個模塊用來負責執行SQL語句,
包含兩個方法,一個是有返回RecordSet的,一個是沒有返回的,
然後組件裏面只要牽涉到數據庫操作,就可以調用這個模塊的兩個方法。
HOHO!
datasource = "Driver={SQL Server};Database=xxxx;server=localhost;uid=xxx;pwd=xxx"
End Function asp中的调用
set test=server.CreateObject("mycom.application")
oconn=test.db_open()
application("strconn")=oconn
如果外部调用condb,会导致连接数据库串暴露出来。建议返回记录集
Public Function rsresult(strsql As String) As Recordset
Dim mycnn As Connection
Dim myset As Recordset
Dim strconnstring As String
Set rsresult = myset
End Function