0

我在 SQL 和文件系统(.dts 文件)中都有 dts pacakege。我想查询两个包以检索包名称数量、任务信息(任务名称等)等信息。

这样做的正确方法是什么?

我尝试执行给出 dts 包列表的命令。但是我不知道如何检索其余信息。执行 msdb..sp_enum_dtspackages

阿图尔

4

1 回答 1

-1

不久前我遇到了同样的问题并找到了答案。请看一下我的脚本,看看它是否有用。

dim strInputFile, strOutputFile

for each arg in WScript.Arguments
    select case mid(arg, 1, 3)
        case "/i:"
            strInputFile = mid(arg, 4)
        case "/o:" 
            strOutputFile = mid(arg, 4)
    end select
next

dim oPackage
set oPackage = CreateObject("DTS.Package2")
oPackage.LoadFromStorageFile strInputFile, "", "", "", ""

dim FileSys, OutputFile
set FileSys = CreateObject("Scripting.FileSystemObject")
set OutputFile = FileSys.OpenTextFile (strOutputFile, 2, 1)

dim oTasks, oProperties
set oTasks = oPackage.Tasks

for each oTask in oTasks
    OutputFile.write (vbCrLf)
    OutputFile.write (string(12 + len(oTask.Description), "-"))
    OutputFile.write (vbCrLf)
    OutputFile.write ("-- Task: "  & oTask.Description & " --") 
    OutputFile.write (vbCrLf)
    OutputFile.write (string(12 + len(oTask.Description), "-"))
    OutputFile.write (vbCrLf)

    set oProperties = oTask.Properties

    for each oProperty in oProperties
        OutputFile.write (oProperty.Name & " = [" & trim(oProperty.Value) & "]")
        OutputFile.write (vbCrLf)
    next 
next 

OutputFile.close

set OutputFile = Nothing
set oTasks = Nothing
set oProperties = Nothing
set oPackage = Nothing
set FileSys = Nothing

关键是要知道从文件系统或 SQL Server 加载 DTS 包的方法。

例如

...
dim oPackage
set oPackage = CreateObject("DTS.Package2")
oPackage.LoadFromStorageFile strInputFile, "", "", "", ""
...

可以在 MSDN 上找到更多详细信息:http:
//msdn.microsoft.com/en-us/library/aa197290%28v=sql.80%29.aspx(LoadFromSQLServer 方法)
http://msdn.microsoft.com/en -us/library/aa197287%28v=sql.80%29.aspx(LoadFromStorageFile 方法)

于 2013-04-18T00:00:13.900 回答