I am trying to change the file that is imported using DTS. Here is my code so far:
[
vb]
'change DTS Package
Dim oPKG As DTS.Package, oStep As DTS.Step
oPKG = New DTS.Package
Dim oConn As DTS.Connection
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 = "CRSERVER"
sUsername = "brenda"
sPassword = "g_Password"
sPackageName = "ImportNewAccurintDataHigh"
' Load Package
oPKG.LoadFromSQLServer(sServer, sUsername, sPassword, _
DTS.DTSSQLServerStorageFlags.DTSSQLStgFlag_UseTrus tedConnection, , , , sPackageName)
'Set Filename
Dim ofd As New OpenFileDialog
With ofd
.Title = "Choose An Excel File"
.InitialDirectory = "C:\Accurint\"
.Filter = "XLS (*.xls)|*.xls|All files (*.*)|*.*"
.FilterIndex = 2
.RestoreDirectory = True
.Multiselect = False
End With
ofd.ShowDialog()
oPKG.Connections.Item("Connection 1").DataSource = ofd.FileName
oConn = Nothing
' 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 = DTS.DTSStepExecResult.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()
oStep = Nothing
oPKG = Nothing
' Display Results
MsgBox(sMessage)
[/
vb]
It is not changing the file though. It is just keeping the same file that is saved in the package already. Anyone have any ideas why?
__________________
Brenda
If it weren't for you guys, where would I be?