Advertisement
Guest User

Untitled

a guest
Mar 16th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.89 KB | None | 0 0
  1. Function Main()
  2.  
  3. dim sServername sServername = ""
  4. dim DestinationFolder DestinationFolder = ""
  5. dim bIntegratedSecurity bIntegratedSecurity= TRUE
  6. dim sLogin sLogin = ""
  7. dim sPassword sPassword = ""
  8.  
  9. dim DocFilename
  10. Dim FileSys
  11. set FileSys = CreateObject("Scripting.FileSystemObject")
  12. MakeSureDirectoryTreeExists(DestinationFolder)
  13. Dim Docfile
  14. Dim oApplication ' As DTS.Application
  15. Dim oPackageSQLServer ' As DTS.PackageSQLServer
  16. Dim oPackageInfos ' As DTS.PackageInfos
  17. Dim oPackageInfo ' As DTS.PackageInfo
  18. Dim oPackage ' As DTS.Package
  19.  
  20. Set oApplication = CreateObject("DTS.Application")
  21. if bIntegratedSecurity then
  22. Set oPackageSQLServer = oApplication.GetPackageSQLServer(sServername,""
  23. ,"" , DTSSQLStgFlag_UseTrustedConnection)
  24. else
  25. Set oPackageSQLServer = oApplication.GetPackageSQLServer(sServername,
  26. sLogin, sPassword, 0)
  27. end if
  28.  
  29. Set oPackageInfos = oPackageSQLServer.EnumPackageInfos("", True, "")
  30.  
  31. Set oPackageInfo = oPackageInfos.Next
  32.  
  33.  
  34. Do Until oPackageInfos.EOF
  35. Set oPackage = CreateObject("DTS.Package2")
  36.  
  37. if bIntegratedSecurity then
  38. oPackage.LoadFromSQLServer sServername, ,
  39. ,DTSSQLStgFlag_UseTrustedConnection , , , , oPackageInfo.Name
  40. else
  41.  
  42. oPackage.LoadFromSQLServer sServername, sLogin,
  43. sPassword,DTSSQLStgFlag_Default , , , , oPackageInfo.Name
  44. end if
  45. DocFilename = DestinationFolder & oPackageInfo.Name & ".txt"
  46. 'msgbox(DocFilename)
  47. If FileSys.FileExists(DocFileName) Then FileSys.DeleteFile(DocFileName)
  48. FileSys.CreateTextFile (DocFileName)
  49.  
  50. set Docfile = FileSys.OpenTextFile (DocFileName,2)
  51. dim oTasks, oProperties
  52. Set oTasks = oPackage.Tasks
  53. For each oTask in oTasks
  54. DocFile.write (vbCrLf)
  55. DocFile.write (vbCrLf)
  56. DocFile.write ("-----TaskDescription:" & oTask.Description)
  57. Set oProperties = oTask.Properties
  58. For Each oProperty In oProperties
  59. DocFile.write (vbCrLf)
  60. DocFile.write ("PropertyName: " & oProperty.Name & " Value=" &
  61. oProperty.Value)
  62. Next
  63. Next
  64. DocFile.close
  65. Set DocFile = Nothing
  66. Set oTasks = Nothing
  67. Set oProperties = Nothing
  68.  
  69. 'oPackage.LogToSQLServer = True
  70. 'oPackage.LogServerName = sServername
  71. 'oPackage.LogServerUserName = sLogin
  72. 'oPackage.LogServerPassword = sPassword
  73. 'oPackage.LogServerFlags = 0
  74. 'oPackage.SaveToSQLServer sServername, sLogin, sPassword,
  75. DTSSQLStgFlag_Default
  76.  
  77. Set oPackage = Nothing
  78. Set oPackageInfo = oPackageInfos.Next
  79. Loop
  80.  
  81. 'Clean up and free resources
  82. Set oApplication = Nothing
  83. Set oPackageSQLServer = Nothing
  84. Set oPackageInfos = Nothing
  85. Set oPackageInfo = Nothing
  86. Set oPackage = Nothing
  87. Set FileSys = Nothing
  88.  
  89. Main = DTSTaskExecResult_Success
  90. End Function
  91.  
  92. Function GetDate(dateVal, delimiter)
  93.  
  94. 'To comply with Option Explict
  95. Dim dateMonth, dateDay
  96.  
  97. dateVal = CDate(dateVal)
  98.  
  99.  
  100. delimiter = CStr(delimiter)
  101.  
  102. dateMonth = Month(dateVal)
  103. dateDay = Day(dateVal)
  104.  
  105. GetDate = CStr(Year(dateVal)) & delimiter
  106.  
  107. If dateMonth < 10 Then
  108. GetDate = GetDate & "0"
  109. End If
  110.  
  111. GetDate = GetDate & CStr(dateMonth) & delimiter
  112.  
  113. If dateDay < 10 Then
  114. GetDate = GetDate & "0"
  115. End If
  116.  
  117. GetDate = GetDate & CStr(dateDay)
  118.  
  119. End Function
  120.  
  121.  
  122. Function MakeSureDirectoryTreeExists(dirName)
  123.  
  124. Dim oFS, aFolders, newFolder, i
  125. Set oFS = CreateObject("Scripting.FileSystemObject")
  126.  
  127.  
  128. If Not oFS.FolderExists(dirName) Then
  129.  
  130. aFolders = split(dirName, "")
  131.  
  132. newFolder = oFS.BuildPath(aFolders(0), "")
  133.  
  134. For i = 1 To UBound(aFolders)
  135. newFolder = oFS.BuildPath(newFolder, aFolders(i))
  136.  
  137. If Not oFS.FolderExists(newFolder) Then
  138. oFS.CreateFolder newFolder
  139. End If
  140. Next
  141. End If
  142.  
  143. Set oFS = Nothing
  144.  
  145. End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement