c#运行加密的dtsx包

时间:2015-01-30 12:04:10

标签: c# encryption ssis

// encrypted file path
    string source = @"C:\Users\cfa\Desktop\encryptedPackage.dtsx";

    // decrypted file destination
    destination = @"C:\Users\cfa\Desktop\test\decryptedPackage.dtsx";

    // read encrypted file
    string text = System.IO.File.ReadAllText(source);

    // decrypted file
    decrypted = crypt.Decryption(text);

    System.IO.File.WriteAllText(destination, decrypted);

    // run decrypted dtsx file - destination
    Microsoft.SqlServer.Dts.Runtime.Application app = new Microsoft.SqlServer.Dts.Runtime.Application();
    Package package = app.LoadPackage(destination, null);
    DTSExecResult pkgResults;
    pkgResults = package.Execute();

    // delete destination file
    File.Delete(destination);

使用前面的代码,我正在运行加密的dtsx包。 我运行解密方法并将结果保存到目标文件并执行该文件。 有没有办法在不创建目标文件的情况下运行包?

1 个答案:

答案 0 :(得分:2)

假设我理解了请求,在内存中你有一个包的XML版本,你希望节省将未加密的位写入磁盘的成本。使用Application类进行实例化的方法不会起作用,因为没有接受流的方法。它需要从磁盘,SQL Server表或包存储中提取。

相反,Package类有一个LoadFromXML方法,应该是您正在寻找的方法。

然后

代码成为

Package package = package.LoadFromXML(decrypted, null);