在 C# 中更改 SSIS 包导致 LoadFromXML 失败

Changing SSIS package in C# causing LoadFromXML fail

我正在尝试创建现有 dtsx 文件的副本,以便我可以根据用户的输入更改一些变量。我能够复制文件,查看变量,并将变量设置为正确的输入。但是,当我查看 Visual Studio 中的文件时,出现了一些错误。

Microsoft Visual Studio 无法加载此文档:程序包无法加载到错误 0xC0010014 "One or more error occurred. There should be more specific errors preceding this one that explains the details of the errors. This message is used as a return value from functions that encounter errors"。当 CPackage::LoadFromXML 失败时会发生这种情况。

错误列表中包含的错误: Error 3 Error loading test.dtsx: Error loading value "<DTS:Property xmlns:DTS="www.microsoft.com/SqlServer/Dts" DTS:Name="PackageFormatVersion">6</DTS:Property>" from node "DTS:Property". E:\test.dtsx 1 1

The version number in the package is not valid. The version number cannot be greater than current version number.

我调查了这些错误,发现了服务器年份和 visual studio 年份的潜在问题。这两个都是2008年的版本。 我的代码:

        string pkgPath = @"\server\TestFolder\test.dtsx"            
        app = new Microsoft.SqlServer.Dts.Runtime.Application();
        pkg = app.LoadPackage(pkgPath, null);

        Console.WriteLine(pkg.Variables["filename"].Value.ToString());
        pkg.Variables["filename"].Value = "testFile";
        Console.WriteLine(pkg.Variables["filename"].Value.ToString());

        app.SaveToXml(pkgPath, pkg, null);

如果我打开我用来在 Visual Studio 中制作副本的文件,它没有问题——当我打开 app.SaveToXML();[=13= 时发生了一些奇怪的事情]

任何想法或建议都会很棒。

至 运行 这是 DTEXEC 的一个进程,它看起来像下面这样。请查看这两个链接以获取有关 ProcessStartInfo 以及如何使用 /SET 的更多详细信息,以便您可以将其添加到您的参数中。首先从命令行对此进行测试,因为语法可能很挑剔。