Reputation: 65
// 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);
With the previous code, i´m running an encrypted dtsx package. I run the decryption method and save the result to a destination file and execute that file. Is there a way to run the package without creating a destinations file?
Upvotes: 0
Views: 440
Reputation: 61201
Assuming I understand the request, in memory you have the XML version of a package and you wish to save the cost of writing the unencrypted bits to disk just to run. The approach of using the Application class to instantiate isn't going to work as there isn't a method that accepts a stream. It needs to pull from disk, from a SQL Server table or the package store.
Instead, the Package class has a LoadFromXML method which should be what you're looking for.
Code then becomes
Package package = package.LoadFromXML(decrypted, null);
Upvotes: 2