Chiamata del pacchetto SSIS in modo asincrono
-
03-07-2019 - |
Domanda
Sto chiamando un pacchetto SSIS usando LoadPackage (...).
È possibile rendere questa chiamata una chiamata asincrona?
Soluzione
Sì, usa un delegato asincrono, come mostrato qui:
Altri suggerimenti
Se vuoi solo che venga eseguito in background, allora sì, puoi eseguire lo spooling di un thread o chiamare un T-SQL per creare dinamicamente un lavoro (e rimuoverlo di nuovo in seguito). Se vuoi eseguirlo in modo asincrono e vuoi una richiamata al termine, sfortunatamente penso che tu sia sfortunato.
Stai chiedendo se è 1) legale chiamare LoadPackage su un thread in background o 2) è possibile. Per # 1 non posso dare una risposta definitiva perché non uso il framework SSIS.
Tuttavia, il numero 2 (purché il numero 1 sia vero) è sicuramente fattibile. IMHO, stai meglio usando un framework esistente che ha API progettate per chiamare l'async dell'API e attendere i risultati. Ad esempio con Parellel Extensions dell'8 giugno CTP, farà il seguente codice.
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
Sto chiamando un pacchetto SSIS dalla mia UI (WPF) tramite una chiamata di servizio WCF asincrona. Il codice di servizio è:
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;
}
}
}
E (parte di) il codice lato client è il seguente:
private void InvokeLoadMarriages()
{
integrationServicesServiceClient.BeginImportMarriageXML(false, OnEndImportMarriageXML, null);
}
private void OnEndImportMarriageXML(IAsyncResult asyncResult)
{
view.InvokeDisplayResults(integrationServicesServiceClient.EndImportMarriageXML(asyncResult));
}
Where BeginImportMarriageXML & amp; EndImportMarriageXML sono le operazioni asincrone generate nella classe proxy.