我正在使用LoadPackage(...)调用SSIS包。
是否可以将此调用设为异步调用?
答案 0 :(得分:1)
是的,请使用异步委托,如下所示:
答案 1 :(得分:0)
如果你只是想让它在后台运行,那么是的,你可以调整一个线程或调用一些T-SQL来动态创建一个作业(然后再删除它)。如果你想异步运行它并想要在完成时回调,那么我认为你很遗憾不幸。
答案 2 :(得分:0)
您是否认为在后台线程上调用LoadPackage是合法的还是2)是否可能。对于#1,我无法给出确定的答案,因为我没有使用SSIS框架。
然而#2(只要#1为真)肯定是可行的。恕我直言,你最好使用现有的框架,该框架的API旨在调用API的异步并等待结果。例如,使用Parellel Extensions 6月08日CTP,下面的代码就可以了。
using System.Threading.Tasks;
...
var future = Future.Create(()=>LoadPackage); // Starts loading the package
// Do other stuff
var package = future.Value; // Wait for package load to complete and get the value
答案 3 :(得分:0)
我通过异步WCF服务调用从我的UI(WPF)调用SSIS包。服务代码是:
public string ImportMarriageXML(bool isWakeUp, bool clearExistingMarriage)
{
try
{
var dts = new Microsoft.SqlServer.Dts.Runtime.Application();
using (var package = dts.LoadFromSqlServer(
ServiceSettings.Settings.SSIS.ImportMarriages,
ServiceSettings.Settings.SSIS.ServerIP,
ServiceSettings.Settings.SSIS.UserID,
ServiceSettings.Settings.SSIS.Password,
null))
{
package.InteractiveMode = false;
package.Connections["DB.STAGING"].ConnectionString = String.Format("{0};Provider={1};", DBSettings.ConnectionString(Core.Database.Staging), ServiceSettings.Settings.SSIS.Provider);
var variables = package.Variables;
variables["IsWakeUp"].Value = isWakeUp;
variables["ClearExistingMarriage"].Value = clearExistingMarriage;
variables["XmlDirectory"].Value = ServiceSettings.Settings.SSIS.Properties.XmlDirectory;
if (package.Execute() == DTSExecResult.Failure)
{
// HACK: Need to refactor this at some point. Will do for now.
var errors = new System.Text.StringBuilder();
foreach (var error in package.Errors)
errors.AppendFormat("SubComponent: {0}; Description: {1}{2}", error.SubComponent, error.Description, Environment.NewLine);
throw new ApplicationException(errors.ToString());
}
return package.Connections["Text Logging"].ConnectionString;
}
}
}
客户端代码的(部分)如下:
private void InvokeLoadMarriages()
{
integrationServicesServiceClient.BeginImportMarriageXML(false, OnEndImportMarriageXML, null);
}
private void OnEndImportMarriageXML(IAsyncResult asyncResult)
{
view.InvokeDisplayResults(integrationServicesServiceClient.EndImportMarriageXML(asyncResult));
}
BeginImportMarriageXML& EndImportMarriageXML是代理类中生成的异步操作。