Llamando al paquete SSIS de forma asíncrona
-
03-07-2019 - |
Pregunta
Estoy llamando a un paquete SSIS usando LoadPackage (...).
¿Es posible hacer que esta llamada sea una llamada asíncrona?
Solución
Sí, use un delegado asíncrono, como se muestra aquí:
Otros consejos
Si solo desea que se ejecute en segundo plano, entonces sí, puede enrollar un hilo o llamar a algunos T-SQL para crear un trabajo dinámicamente (y eliminarlo de nuevo más tarde). Si desea ejecutarlo de forma asíncrona y desea una devolución de llamada cuando haya terminado, creo que lamentablemente no tendrá suerte.
¿Está preguntando si es 1) legal llamar a LoadPackage en un subproceso en segundo plano o 2) si es posible? Para el # 1 no puedo dar una respuesta definitiva porque no uso el marco SSIS.
Sin embargo, # 2 (siempre que # 1 sea verdadero) es definitivamente factible. En mi humilde opinión, es mejor utilizar un marco existente que tiene API diseñadas para llamar a API async y esperar los resultados. Por ejemplo, con Parellel Extensions June 08 CTP, el siguiente código servirá.
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
Estoy llamando a un paquete SSIS desde mi interfaz de usuario (WPF) a través de una llamada de servicio asíncrona WCF. El código de servicio es:
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;
}
}
}
Y (parte de) el código del lado del cliente es el siguiente:
private void InvokeLoadMarriages()
{
integrationServicesServiceClient.BeginImportMarriageXML(false, OnEndImportMarriageXML, null);
}
private void OnEndImportMarriageXML(IAsyncResult asyncResult)
{
view.InvokeDisplayResults(integrationServicesServiceClient.EndImportMarriageXML(asyncResult));
}
Donde BeginImportMarriageXML & amp; EndImportMarriageXML son las operaciones asíncronas generadas en la clase proxy.