This last week I was approached by a customer that wanted to run an SSIS package (that created the data for the Map) but sometimes that task wasn’t finishing before SmartConnect needed to use the result of that task as a data source. In this instance, the desired result wasn’t to run the tasks as quickly as possible but to make sure this task was completed before we move on to the next task or process. Below we will discuss the simple steps that you can run from a script to handle this scenario:
1) Create a new Script Task on the Map Pre Tasks section to Run before the map(Inside the Map-Tasks-Map Pre Tasks-Tasks that run before the map-Right Click and select New Task-Run Script) and name it SYNC_TASK like in the image below:
2) Now we will use the following script to start a process and ensure that the next step isn’t attempted until this task completes. In our example we will simply open notepad.exe and wait to move on until the product is closed. This same methodology could be applied to a stored procedure or SSIS package or even calling an external web service. The image below shows the example in VB.NET but you can use either.
Here is the script in both VB.NET and C# formats below:
VB.NET
‘Specify the location of the Notepad.exe file
Dim filename As String = “C:WindowsSystem32Notepad.exe”
‘Specify the parameters you want to run on the file
‘This example passes in one parameter that indicates which file it should open
Dim fileparameters As String = “file.txt”
‘This next step runs the file passing in the parameters
Dim process = System.Diagnostics.Process.Start(filename, fileparameters)
‘Do not proceed until the process is complete
‘In our example, wait until Notepad.exe is closed
process.WaitForExit()
return true
C#
//Specify the location of the Notepad.exe file
string filename = “C:\Windows\System32\Notepad.exe”;
//Specify the parameters you want to run on the file
//This example passes in one parameter that indicates which file it should open
string fileparameters = “file.txt”;
//This next step runs the file passing in the parameters
System.Diagnostics.Process process = System.Diagnostics.Process.Start(filename, fileparameters);
//Do not proceed until the process is complete
//In our example, wait until Notepad.exe is closed
process.WaitForExit();
return true;
3) Run the Map by selecting the Run Map function on the Ribbon while your map is selected (this can also be done from inside the map by selecting Run when it is open).
4) In our scenario, the Notepad.exe program will launch and nothing else will continue with SmartConnect until we close the Notepad.exe application. Once Notepad is closed, the rest of the map will execute as planned.
As you can see in this simple example, we can ensure a task is finished by using standard .NET functionality.
Thanks,
Chris