adwiseman
asked on
Looping in DTS
I have a DTS Package THAT Loops
The function that causes it too loop is at the end of this post.
In part of my loop, I change the datasource to a different access database each time I loop, but the connection never changes. I've experienced this before, and worked around it by executing a second dTS package that did the datapump. Has anyone else tried this. It appears that once I use a connection, I can not change that connections datasource.
How do you change the datasource of a connection after you have used that connection in the DTS package.
'************************* ********** ********** ********** ********** *****
' Visual Basic ActiveX Script
'************************* ********** ********** ********** ********** *******
Function Main()
DIM oPkg
Set oPkg = DTSGlobalVariables.Parent
IF DTSGlobalVariables("DestMD B").Value <> "" THEN
Dim oConn
Set oConn = DTSGlobalVariables.Parent. Connection s("Microso ft Access Copy")
oConn.DataSource = DTSGlobalVariables("DestMD B").Value
Set oConn = Nothing
oPkg.Steps("DTSStep_DTSAct iveScriptT ask_1").Ex ecutionSta tus = DTSStepExecStat_Waiting
oPkg.Steps("DTSStep_DTSExe cuteSQLTas k_4").Exec utionStatu s = DTSStepExecStat_Waiting
oPkg.Steps("DTSStep_DTSDyn amicProper tiesTask_2 ").Executi onStatus = DTSStepExecStat_Waiting
oPkg.Steps("DTSStep_DTSDat aPumpTask_ 2").Execut ionStatus = DTSStepExecStat_Waiting
oPkg.Steps("DTSStep_DTSAct iveScriptT ask_4").Ex ecutionSta tus = DTSStepExecStat_Waiting
oPkg.Steps("DTSStep_DTSExe cuteSQLTas k_5").Exec utionStatu s = DTSStepExecStat_Waiting
Main = DTSStepScriptResult_DontEx ecuteTask
Else
Main = DTSTaskExecResult_Success
END IF
Main = DTSTaskExecResult_Success
End Function
The function that causes it too loop is at the end of this post.
In part of my loop, I change the datasource to a different access database each time I loop, but the connection never changes. I've experienced this before, and worked around it by executing a second dTS package that did the datapump. Has anyone else tried this. It appears that once I use a connection, I can not change that connections datasource.
How do you change the datasource of a connection after you have used that connection in the DTS package.
'*************************
' Visual Basic ActiveX Script
'*************************
Function Main()
DIM oPkg
Set oPkg = DTSGlobalVariables.Parent
IF DTSGlobalVariables("DestMD
Dim oConn
Set oConn = DTSGlobalVariables.Parent.
oConn.DataSource = DTSGlobalVariables("DestMD
Set oConn = Nothing
oPkg.Steps("DTSStep_DTSAct
oPkg.Steps("DTSStep_DTSExe
oPkg.Steps("DTSStep_DTSDyn
oPkg.Steps("DTSStep_DTSDat
oPkg.Steps("DTSStep_DTSAct
oPkg.Steps("DTSStep_DTSExe
Main = DTSStepScriptResult_DontEx
Else
Main = DTSTaskExecResult_Success
END IF
Main = DTSTaskExecResult_Success
End Function
http://www.sqldts.com/default.aspx?246
ASKER
I know how to make my DTS loop, I posted the code.
I need to change the database connection each time a loop to a different database, and I need it to actualy change the connection. Traditional methonds of driving the connection using a global variable only works the first time I set it. Once I use the connection just once in the DTS package, I can not change the connection again.
I need to change the database connection each time a loop to a different database, and I need it to actualy change the connection. Traditional methonds of driving the connection using a global variable only works the first time I set it. Once I use the connection just once in the DTS package, I can not change the connection again.
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
Found it.
There is a property of the Access Connection called Reusable = -1 by default. This causes the connection to be cached and does not change once established even if you change the datasource. Set Reusable = 0, and the connection will refresh when it's datasource is changed.
There is a property of the Access Connection called Reusable = -1 by default. This causes the connection to be cached and does not change once established even if you change the datasource. Set Reusable = 0, and the connection will refresh when it's datasource is changed.
Great and thanks for the admittedly not deserved points.
Totally unrelated, but you can simplify and check for failure in your code as follows:
Function Main()
DIM oPkg
Set oPkg = DTSGlobalVariables.Parent
IF DTSGlobalVariables("DestMD B").Value <> "" THEN
' Dim oConn
' Set oConn = DTSGlobalVariables.Parent. Connection s("Microso ft Access Copy")
' oConn.DataSource = DTSGlobalVariables("DestMD B").Value
' Set oConn = Nothing
oPkg.Connections("Microsof t Access Copy").DataSource = DTSGlobalVariables("DestMD B").Value
oPkg.Steps("DTSStep_DTSAct iveScriptT ask_1").Ex ecutionSta tus = DTSStepExecStat_Waiting
oPkg.Steps("DTSStep_DTSExe cuteSQLTas k_4").Exec utionStatu s = DTSStepExecStat_Waiting
oPkg.Steps("DTSStep_DTSDyn amicProper tiesTask_2 ").Executi onStatus = DTSStepExecStat_Waiting
oPkg.Steps("DTSStep_DTSDat aPumpTask_ 2").Execut ionStatus = DTSStepExecStat_Waiting
oPkg.Steps("DTSStep_DTSAct iveScriptT ask_4").Ex ecutionSta tus = DTSStepExecStat_Waiting
oPkg.Steps("DTSStep_DTSExe cuteSQLTas k_5").Exec utionStatu s = DTSStepExecStat_Waiting
' Main = DTSStepScriptResult_DontEx ecuteTask
Main = DTSTaskExecResult_Success
Else
' Main = DTSTaskExecResult_Success
Main = DTSTaskExecResult_Failure
END IF
' Main = DTSTaskExecResult_Success
End Function
Totally unrelated, but you can simplify and check for failure in your code as follows:
Function Main()
DIM oPkg
Set oPkg = DTSGlobalVariables.Parent
IF DTSGlobalVariables("DestMD
' Dim oConn
' Set oConn = DTSGlobalVariables.Parent.
' oConn.DataSource = DTSGlobalVariables("DestMD
' Set oConn = Nothing
oPkg.Connections("Microsof
oPkg.Steps("DTSStep_DTSAct
oPkg.Steps("DTSStep_DTSExe
oPkg.Steps("DTSStep_DTSDyn
oPkg.Steps("DTSStep_DTSDat
oPkg.Steps("DTSStep_DTSAct
oPkg.Steps("DTSStep_DTSExe
' Main = DTSStepScriptResult_DontEx
Main = DTSTaskExecResult_Success
Else
' Main = DTSTaskExecResult_Success
Main = DTSTaskExecResult_Failure
END IF
' Main = DTSTaskExecResult_Success
End Function
ASKER
It works like this
IF DTSGlobalVariables("DestMD B").Value <> "" THEN
setup for looping and start the loop,
also flag myself as not executed, so the steps after my loop don't begin.
ELSE
indicating I've executed the last loop, and I should not loop anymore
Set my results to success so the steps to folow will begin
IF DTSGlobalVariables("DestMD
setup for looping and start the loop,
also flag myself as not executed, so the steps after my loop don't begin.
ELSE
indicating I've executed the last loop, and I should not loop anymore
Set my results to success so the steps to folow will begin
ASKER
DestMDB is empty after my last loop