我正在尝试编写故障排除功能。执行之前,在编译时在Test2中收到数据类型不匹配错误。 GetExecutionErrorInfo的第二个参数在错误时突出显示。这些是SQL Server 2000 DTS程序包,而不是SSIS。任何帮助将不胜感激。
环境: -在运行Windows 7 Enterprise 64位的PC上,在Microsoft Access 365中编写VBA代码,并安装了Microsoft SQL Server Management Studio -数据库–服务器上的SQL Server 2008R2
链接到测试应用程序的库:Microsoft DTSPackage对象库,Microsoft DTS自定义任务对象库,Microsoft DTS Runtime 1.0,Microsoft DTSDataPump脚本对象库
错误-编译错误:ByRef参数类型不匹配
Sub DTS_via_VBA()
Dim oPkg As New DTS.Package
Dim oStep As DTS.Step
Dim strPackageName, strServer As String
' define the connection to the production server
strServer = "XYZ\SQL01"
strPackageName = "DTS_Package_Name"
' load the package
oPkg.LoadFromSQLServer strServer, , , DTSSQLStgFlag_UseTrustedConnection, , , , strPackageName
' Set Exec on Main Thread
For Each oStep In oPkg.Steps
oStep.ExecuteInMainThread = True
Next
' execute the package
oPkg.Execute
'test step's success
Call Test2(oPkg)
' cleanup details
Set oStep = Nothing
oPkg.UnInitialize
Set oPkg = Nothing
End Sub
Sub Test2(ByRef oPkg As DTS.Package)
Dim i As Integer
Dim l1 As Long
Dim s1, s2 As String
For i = 1 To oPkg.Steps.Count
If oPkg.Steps(i).ExecutionResult = DTSStepExecResult_Failure Then
oPkg.Steps(i).GetExecutionErrorInfo l1, s1, s2
End If
Next i
End Sub