我正在尝试从vba运行dts包,我现在的代码如下,我已经删除了服务器和密码,但我知道密码是正确的。
我试图在服务器前放置“//”以查看它是否有效但是没有(SQL数据库位于我尝试运行VBA代码的单独服务器上那件事)
Sub ExecutePackage()
Dim oPKG As DTS.Package, oStep As DTS.Step
Set oPKG = New DTS.Package
Dim sServer As String, sUsername As String, sPassword As String
Dim sPackageName As String, sMessage As String
Dim lErr As Long, sSource As String, sDesc As String
' Set Parameter Values
sServer = "xxxxxxx"
sUsername = "xx"
sPassword = "xxxxxxxxxxxxx"
sPackageName = "PODs Import"
' Load Package
oPKG.LoadFromSQLServer sServer, sUsername, sPassword, _
DTSSQLStgFlag_Default, , , , sPackageName
' Set Exec on Main Thread
For Each oStep In oPKG.Steps
oStep.ExecuteInMainThread = True
Next
' Execute
oPKG.Execute
' Get Status and Error Message
For Each oStep In oPKG.Steps
If oStep.ExecutionResult = DTSStepExecResult_Failure Then
oStep.GetExecutionErrorInfo lErr, sSource, sDesc
sMessage = sMessage & "Step """ & oStep.Name & _
""" Failed" & vbCrLf & _
vbTab & "Error: " & lErr & vbCrLf & _
vbTab & "Source: " & sSource & vbCrLf & _
vbTab & "Description: " & sDesc & vbCrLf & vbCrLf
Else
sMessage = sMessage & "Step """ & oStep.Name & _
""" Succeeded" & vbCrLf & vbCrLf
End If
Next
oPKG.UnInitialize
Set oStep = Nothing
Set oPKG = Nothing
' Display Results
MsgBox sMessage
End Sub
错误我得到了
编辑: 发现这不是与VBA代码有关,而是与本地有关,因为在cmd上通过DTSrun运行它不起作用。