2009-01-02 31 views

回答

0

如果您只是希望它在後臺運行,那麼您可以將線程暫停或調用某些T-SQL來動態創建作業(並在之後再次將其刪除)。如果你想異步運行它,並且在完成時想要回調,那麼我認爲你很不幸運。

0

你是問,如果是1)合法的調用loadpackage在後臺線程或2)是否有可能。對於#1我不能給出明確的答案,因爲我不使用SSIS框架。

然而#2(只要#1是真的)肯定是可行的。恕我直言,你最好使用現有的框架,其API設計爲調用API的異步並等待結果。例如,如果使用Parellel Extensions June 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 
0

我正在通過異步WCF服務調用從我的用戶界面(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被中相應的代理類生成的異步操作。