我打算将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

解决方案 »

  1.   

    First of all, why do you want to hardcode the server and password in a DLL.  You can create an ODBC in Control Panel -> Administrative Tools -> Data Source.  Then you reference the ODBC name in your DLL.Second, you can do a Public Property Get/Set on condb to expose the condb object.
      

  2.   

    Public property Get GetConDB() As Object
        Set ConDB=condb
    End Property
      

  3.   

    不要將連接字符串放在組件中,你可以讀取一個配置文件來獲得連接字符串。
    其實可以這樣VB組件一個模塊用來負責執行SQL語句,
    包含兩個方法,一個是有返回RecordSet的,一個是沒有返回的,
    然後組件裏面只要牽涉到數據庫操作,就可以調用這個模塊的兩個方法。
    HOHO!
      

  4.   

    dim A as yourdllset a=new yourdlla.opendb(dbstr)
      

  5.   

    Public  Function  db_open()  As  Variant 
    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