Sunday, July 16, 2006

SQL: How to check for a parallel run of a DTS package

What will happen if the DTS/ SSIS package is running as per schedule, and if some one else manually tries to execute the same package. In the normal scenario, the package will be executed in two threads.

Here is a script by which we can check if the DTS package is already running or not. Have this check as the first step within the package. So even if some one executes a second session of the package, the package is intelligent enough not to run.

Prerequisites: Have a global variable declared as string: Variable1
Whenever the DTS package is executed, make an entry to a table in the database. This can be the table used to track the execution of the DTS packages (In the below example the table name is 'dtsLog' and column 'DTSStatus' has the value related to DTS status). dtsParent is the name of the package for which we are putting this check condition.

'**********************************************************************'
Visual Basic ActiveX Script'
************************************************************************
Function Main()

Dim oAdoConn
Set oAdoConn = CreateObject("adodb.Connection")

oAdoConn.ConnectionString = "Driver={SQL Server};Server=" & DTSGlobalVariables("Variable1").Value & ";Database=<database name>;Trusted_Connection=Yes"
oAdoConn.Open

Set rsCount = oAdoConn.Execute("SELECT DTSStatus FROM dtsLog WHERE (dtsName= 'dtsParent')")

If rsCount.Fields("DTSStatus") = "Started" then
Main = DTSTaskExecResult_Failure
Else
Main = DTSTaskExecResult_SuccessEnd If
End Function


GetTechieHere...

0 Comments:

Post a Comment

<< Home