之前我曾经问过一个模糊的问题(虽然特定于从xp_cmdshell运行包)。我对此事的最后评论是,如果我想确保SSIS一揽子计划参与交易,我会问我的选择是什么。
那么,有没有办法可以执行SSIS包并让它参与已经存在的交易?
如果出于测试目的,我们想要:
谢谢, 斯图尔特。
答案 0 :(得分:2)
互联网对这个问题的解决方案非常安静。我有同样的问题,到处寻找解决方案。 SSIS对于执行错误时生成的错误消息(未记录的错误代码)也没有帮助。答案可能有点晚,但希望它能帮助别人避免浪费时间。这就是最终为我工作的原因。
在单元测试中,例如将整个过程包装在TransactionScope中:
using (TransactionScope scope = new TransactionScope(TransactionScopeOption.RequiresNew,new TransactionOptions(){IsolationLevel =IsolationLevel.ReadCommitted}))
{
Application app = new Application();
Package package = app.LoadPackage(packageFileName, null);
// Can set package settings for test
package.TransactionOption = DTSTransactionOption.Required;
package.IsolationLevel = IsolationLevel.ReadCommitted;
// Use this overload for execute
DTSExecResult result = package.Execute(null, null, null, null, TransactionInterop.GetDtcTransaction(Transaction.Current));
// Test results here inside the scope
}
当然,如果要将数据添加到数据库,然后通过SSIS提取数据,然后在测试数据后回滚,则可以重新排列。