home
Script dTS package properties
Author Nigel Rivett
The following will create a file including the properties of a dts package. Useful for searching or detecting changes.
The files will be created in the folder of the global variable "Path" and be named .txt.
Create a dts package with the following globale variables
Global Variables
ServerName
Path
UserName
Password
Create a Activex Script Task and include the following script.
Call it via (for a trustedt connection include a blank uid/password)
declare @sql varchar(1000)
select @sql = 'dtsrun /NScript_DTS_Packages /S(local) /E '
+ '/A"ServerName":8="' + (local) + '" '
+ '/A"Path":8="' + c:\test\ + '" '
+ '/A"UserName":8="' + myuid + '" '
+ '/A"Password":8="' + mypwd + '" '
exec master..xp_cmdshell @sql
Activex Script
'**********************************************************************
' Visual Basic ActiveX Script
'************************************************************************
Function Main()
Dim sServerName
Dim sPath
Dim sUserName
Dim sPassword
Dim iTrusted
sServerName = DTSGlobalVariables("ServerName").Value
sPath = DTSGlobalVariables("Path").Value
sUserName = DTSGlobalVariables("UserName").Value
sPassword = DTSGlobalVariables("Password").Value
if len(sUserName) = 0 then
iTrusted = "Y"
else
iTrusted = "N"
end if
iTrusted = "Y"
ScriptDTSPackages sServerName, sPath, iTrusted, sUserName, sPassword
Main = DTSTaskExecResult_Success
End Function
Private Sub ScriptDTSPackages(sServerName, sPath, iTrusted, sUserName, sPassword)
Dim objCon
Dim objCmd
Dim objRsPackageNames
Set objCon = CreateObject("ADODB.Connection")
if iTrusted = "Y" then
objCon.ConnectionString = "Provider=sqloledb;" & _
"Data Source=" & sServerName & ";" & _
"Initial Catalog=" & "msdb" & ";" & _
"Integrated Security=SSPI"
else
objCon.ConnectionString = "Provider=sqloledb;" & _
"Data Source=" & sServerName & ";" & _
"User Id=" & sUserName & ";" & ";" & _
"Password=" & sPassword & ";" & _
"Initial Catalog=" & "msdb"
end if
objCon.CursorLocation = 3 'adUseClient
objCon.Open
Set objCmd = CreateObject("ADODB.Command")
objCmd.ActiveConnection = objCon
objCmd.CommandType = 1 'adCmdText
objCmd.CommandText = "select distinct name from sysdtspackages order by name"
Set objRsPackageNames = CreateObject("ADODB.Recordset")
Set objRsPackageNames = objCmd.Execute
'ScriptDTSPackage "alantest", frmInitial.txtFolder, frmInitial.txtServer, frmInitial.chkTrusted, frmInitial.txtUsername, frmInitial.txtPassword
Do While Not objRsPackageNames.EOF
ScriptDTSPackage2 objRsPackageNames("Name"), sPath, sServerName, iTrusted, sUserName, sPassword
objRsPackageNames.MoveNext
Loop
Set objRsPackageNames = Nothing
Set objCmd = Nothing
Set objCon = Nothing
End Sub
Private Sub ScriptDTSPackage2(sPackageName, sFolder, sServer, iTrusted, sUID, sPWD)
Dim objFileScript
Dim objFStream
Dim objDTSPackage
Dim objDTSTask
Dim objDTSConnection
Dim objDTSTransformation
Dim objDTSDataPumpTask
Dim objDTSGlobalVariable
Dim objDTSCustomTask
Dim objDTSProperty
Dim objDTSDynamicPropertiesTask
Dim objDTSDynamicPropertiesTaskAssignment
Dim i
Dim s1
Dim s2
Set objFileScript = CreateObject("Scripting.FileSystemObject")
Set objFStream = objFileScript.CreateTextFile(sFolder & sPackageName & "_properties.txt")
' load package
Set objDTSPackage = CreateObject("DTS.Package2")
If iTrusted = "Y" Then
objDTSPackage.LoadFromSQLServer sServer, , , 256, , , , sPackageName
Else
objDTSPackage.LoadFromSQLServer sServer, sUID, sPWD, , , , , sPackageName
End If
' Global variables
objFStream.WriteLine "************************"
objFStream.WriteLine "Global Variables"
objFStream.WriteLine "************************"
For Each objDTSGlobalVariable In objDTSPackage.GlobalVariables
objFStream.WriteLine "<" & objDTSGlobalVariable.name & "=" & objDTSGlobalVariable.value & ">"
Next
' connections
objFStream.WriteBlankLines 2
objFStream.WriteLine "************************"
objFStream.WriteLine "Connections"
objFStream.WriteLine "************************"
For Each objDTSConnection In objDTSPackage.Connections
objFStream.WriteLine "<ID=" & objDTSConnection.ID & ">" & "<name=" & objDTSConnection.Name & ">" & "<Source=" & objDTSConnection.DataSource & ">" & "<ProviderID=" & objDTSConnection.ProviderID & ">"
Next
' tasks
objFStream.WriteBlankLines 2
objFStream.WriteLine "************************"
objFStream.WriteLine "Tasks"
objFStream.WriteLine "************************"
For Each objDTSTask In objDTSPackage.Tasks
objFStream.WriteLine "<type=" & objDTSTask.CustomTaskID & ">" & "<name=" & objDTSTask.Name & ">" & "<Description=" & objDTSTask.Description & ">"
' executesql task
If objDTSTask.CustomTaskID = "DTSExecuteSQLTask" Then
objFStream.WriteLine "<sql statement>"
objFStream.WriteLine objDTSTask.Properties("SQLStatement")
objFStream.WriteLine "<sql statement end>"
' datapump task
ElseIf objDTSTask.CustomTaskID = "DTSDataPumpTask" Then
objFStream.WriteLine "<SourceObjectName=" & objDTSTask.Properties("SourceObjectName") & ">" & "<SourceConnectionID=" & objDTSTask.Properties("SourceConnectionID") & ">"
If objDTSTask.Properties("SourceSQLStatement") <> "" Then
objFStream.WriteLine "<source sql statement>"
objFStream.WriteLine objDTSTask.Properties("SourceSQLStatement")
objFStream.WriteLine "<source sql statement end>"
End If
objFStream.WriteLine "<DestinationObjectName=" & objDTSTask.Properties("DestinationObjectName") & ">" & "<DestinationConnectionID=" & objDTSTask.Properties("DestinationConnectionID") & ">"
Set objDTSDataPumpTask = objDTSTask.CustomTask
objFStream.WriteLine "<transformations=" & ">"
For Each objDTSTransformation In objDTSDataPumpTask.Transformations
For i = 1 To objDTSTransformation.DestinationColumns.Count
objFStream.WriteLine objDTSTask.Properties("SourceObjectName") & "." & objDTSTransformation.SourceColumns(i).Name & " --> " & objDTSTask.Properties("DestinationObjectName") & "." & objDTSTransformation.DestinationColumns(i).Name
Next
Next
objFStream.WriteLine "<transformations=" & " end>"
' dynamic proprties task
ElseIf objDTSTask.CustomTaskID = "DTSDynamicPropertiesTask" Then
Set objDTSDynamicPropertiesTask = objDTSTask.CustomTask
For Each objDTSDynamicPropertiesTaskAssignment In objDTSDynamicPropertiesTask.Assignments
If objDTSDynamicPropertiesTaskAssignment.SourceType = 0 Then
s1 = "<INIFile=" & objDTSDynamicPropertiesTaskAssignment.SourceIniFileFileName & ">" & "<key=" & objDTSDynamicPropertiesTaskAssignment.SourceIniFileSection & "." & objDTSDynamicPropertiesTaskAssignment.SourceIniFileKey & ">"
End If
s2 = " --> " & "<" & objDTSDynamicPropertiesTaskAssignment.DestinationPropertyID & ">"
objFStream.WriteLine s1 & s2
Next
' Activex script task
ElseIf objDTSTask.CustomTaskID = "DTSActiveScriptTask" Then
objFStream.WriteLine "<ActiveXScript>"
objFStream.WriteLine objDTSTask.Properties("ActiveXScript")
objFStream.WriteLine "<ActiveXScript end>"
' Creae Proecss task
ElseIf objDTSTask.CustomTaskID = "DTSCreateProcessTask" Then
objFStream.WriteLine "<ProcessCommandLine>"
objFStream.WriteLine objDTSTask.Properties("ProcessCommandLine")
objFStream.WriteLine "<ProcessCommandLine end>"
' Send Mail task
ElseIf objDTSTask.CustomTaskID = "DTSSendMailTask" Then
Set objDTSCustomTask = objDTSTask.CustomTask
For Each objDTSProperty In objDTSCustomTask.Properties
objFStream.WriteLine objDTSProperty.name & "=" & objDTSProperty.value
Next
' FTP task
ElseIf objDTSTask.CustomTaskID = "DTSFTPTask" Then
For Each objDTSProperty In objDTSTask.Properties
objFStream.WriteLine objDTSProperty.name & "=" & objDTSProperty.value
Next
' Trasnfer Objects task
ElseIf objDTSTask.CustomTaskID = "DTSTransferObjectsTask" Then
Set objDTSCustomTask = objDTSTask.CustomTask
For Each objDTSProperty In objDTSCustomTask.Properties
objFStream.WriteLine objDTSProperty.name & "=" & objDTSProperty.value
Next
Else
objFStream.WriteLine "**********************" & objDTSTask.Name & " task name not catered for **********************"
End If
objFStream.WriteBlankLines 2
Next
objFStream.Close
Set objFStream = Nothing
Set objDTSPackage = Nothing
End Sub
home