Sub initConfig()
On Error GoTo bottom
Dim xml
Set xml = CreateObject("Msxml2.DOMDocument")
xml.Load (XMLPATH)
Dim root
Set root = xml.documentElement
Dim node
Dim nodeList
Set nodeList = root.getElementsByTagName("APPLICATION")
Dim AppName As String
Dim uid As String
Dim pwd As String
Dim TNS As String
Redim DBConfig(nodeList.length)
For i = 1 To nodeList.length
Set node = nodeList.Item(i-1)
If (node.nodeType = 1 And node.hasChildNodes()) Then
DBConfig(i).AppName = Ucase(node.Attributes.getNamedItem("name").Text)
DBConfig(i).DB_UID = node.selectSingleNode("USERID").Text
DBConfig(i).DB_PWD = node.selectSingleNode("PASSWORD").Text
DBConfig(i ).DB_TNS = node.selectSingleNode("TNS").Text
End If
Next
bottom:
Exit Sub
End Sub
' ///////////////////////////////////////////////////////////////////////////////////////////////////////
' Author : ivy8890
' Created : 2005/04/15
' Purpose : Get specified application config information.
' Return : (1) >0 index of DBConfig
' (2) err : 0
'
' History : <<< ID : 999 Type[Add, Update, Del] Start yyyy/mm/dd Department Purpose >>>
' XXXXXXXXXXXXXXXXXXXXXXXXXXXX
' <<< ID : 999 Type[Add, Update, Del] End yyyy/mm/dd Department>>>
'
' ///////////////////////////////////////////////////////////////////////////////////////////////////////
Function getDBConfig(sname As String) As Integer
getDBConfig = 0
DB_Result = 0
On Error GoTo bottom
Call initConfig
For i = 1 To Ubound(DBConfig)
If (Ucase(DBConfig(i).AppName) = Ucase(sname)) Then
getDBConfig = i
DB_Result = i
DB_UID = DBConfig(i).DB_UID
DB_PWD = DBConfig(i).DB_PWD
DB_TNS = DBConfig(i).DB_TNS
Exit For
End If
Next
bottom:
Exit Function
End Function
四、 配置和使用
为了使多个应用使用,将以上代码保存为DBConfig.lss。*.Lss文件位置 : Server端 Lotus\domino目录下;Client端 Lotus\notes目录下。
(1)导入Lss文件
如果DBConfig.lss放在Lotus\notes目录下,使用时要用Include语句,%Include “DBConfig.lss”; 如果放在Lotus\notes\lss目录下,要用%Include “lss/DBConfig.lss”。
(2)调用getDBConfig
以字符型 Application Name 为参数调用getDBConfig(AppName),此AppName应于DBConfig.xml文件中<APPLICATION>的name属性值一致,不区分大小写。返回值为整型,如果返回值为零,表示出错或没有找到对应APPLICATION;如果返回值大于零,表示正常,返回值为其在DBConfig数组中的位置,UserID 和Password等可以用DBConfig(返回值). DB_UID和DBConfig(返回值). DB_PWD取得,也可以直接使用DB_UID和DB_PWD取得。
(3)和ScriptLib一块使用
在ScriptLib中新建DBConfig导入DBConfig.lss,在Sub Initialize中以字符型 Application Name 为参数调用getDBConfig(AppName),在Agent中使用Use语句:Use "DBConfig",在取得UserID 和Password处,先用DB_Result判断,DB_Result大于零时,正常;等于零时,出错。正常时等可以用DBConfig(DB_Result). DB_UID和DBConfig(DB_Result). DB_PWD取得,也可以直接使用DB_UID和DB_PWD取得。
注意: 如果Server端没用安装注册Microsoft XML v3.0,会出现429错误,需要安装注册Microsoft XML v3.0。 以下是安装注册过程:
1)拷贝文件msxml3.dll、msxml3a.dll、msxml3r.dll到C:\Winnt\System32目录下。
2)在MS-Dos下转到C:\Winnt\System32目录,执行命令:regsvr32 C:\WINNT\system32\msxml3.dll
五、追加、变更、删除
(1)追加
DBConfig.xml 中追加<APPLICATION>元素,Lotus Script Agent中追加调用。
(2)变更
只需对DBConfig.xml中的相应<APPLICATION>元素进行变更。
(3)删除
在Lotus Script Agent中删除调用后,对应的DBConfig.xml中可以删除也可以不删除。