Cannot put a SQL Task within a Foreach Loop - sql-server

I am new to SSIS and I am relying on a book, so this should be an easy question to answer.
I want to import data from all of the text files within a directory. So I create a Foreach container.
The first thing I want to do within the loop is execute a SQL task to drop and create the landing table.
Then I want to load the data into the landing table from the selected text file using a Data Flow task.
Then I want to execute a SQL Task to load the SQL tables from the Landing table and do some calculations.
The problem is that within a Foreach loop, I cannot connect up a SQL Task to a Data Flow task. The message I get is
Cannot create connector. Cannot
connect the executables from different
containers.
So how do I do this?

How about a screen shot? I've used these 2 components in a loop container before with no problem, my guess is the GUI is a little deceptive here.

I know this is an old thread. I wanted to add to it though in case it is helpful to anybody.
In my case, I had the foreach loop container with some FTP Tasks and Script Tasks in it and I still need to add more within this foreach loop. I renamed the foreach loop and then added a new Script Task at the bottom of the flow of the foreach loop container. When I tried to connect the current FTP Task at the end of the flow of the foreach loop container to the new Script Task that I'd added at the bottom, I got the error about "Cannot create connector. Cannot connect the executables from different containers."
So I dragged the current FTP Tasks and Script Tasks outside of the newly renamed foreach loop container (or I suspect I could have cut them and pasted them outside the foreach loop container). I then dragged them all back into the newly renamed foreach loop container. I then connected them all again successfully without getting this error.
So it seems that once you rename a foreach loop container WITHOUT being done completely, when you add a new Task icon to the bottom of the flow of the newly renamed foreach loop container you might or will get the error about not being able to connect from different containers (since I guess the newly renamed foreach loop container is considered to be "different" than the old name of the very same foreach loop container.

I've had a similar problem, where is looked as though both the components were in the for loop. Whereas (similar to rageit's comment) one of the sub-compnents were actually on-top rather than within the foreach loop.
The quick fix was to cut the component, select the foreach loop and paste it in.

It looks like you are trying to connect a Sql Task within a foreach loop to a DataFlow task that is not in the loop. If that is what you are intending, you need to take the connection from the ForEach loop and connect it to the DataFlow. If, however, you want both the SQLTask and the Dataflow to run within the ForEachLoop, you need to put the DataFlow into the ForEach loop and then you will be able to connect the SQLTask to the DataFlow.

None was my case. I just moved it from different container to a new container. I had to recreate the task. There is no property to show you what container is holding the task. Definitely GUI bug. I'm using BI 2008

Solution that solved my problem is cut the component and paste it back. If there is a heirarchy of tasks cut all tasks one by one to delete their connections and paste them back and then connect from the top.

Related

Share database connection between many structs

In my program I need to share connection between many struct for updating data in database.
I use rusqlite for my database
and egui for my GUI
Here my source code.
I put a FIXME in the file counter.rs.
I implemented Widget for displaying data easily.
And when I click on a button I would like to perform a SQL UPDATE ... request but I cannot get database connection.
Thank for you help.
I think I found a solution with the singleton DP but I think it's a bad way to do it.
You may want to separate data from interface - create a separate struct for the Counter UI which holds a DB reference and a copy of the Counter data. Then you can straightforwardly construct such a Counter UI object when you instantiate your counter app, passing your DB connection onwards.

Insert status of SSIS package in SQL Table

My project consist of creating multiple sub directories and copy files to those sub directories. I developed this part using file system task inside a foreach loop in SSIS.
The final part is insert into SQL Table, the status of the process. If the file was copy successful the Status column should be "Successful" and the reason in another column should be "File was copied successfully" or something like that.
The error flow redirection (red arrow) is available for file system task or foreach loop? I have read somewhere that in event handlers you can work these status messages and insert them in SQL. Could someone please provide a solution or suggest one to solve this problem?
I would steer away from using event handlers. They are like hidden GOTOs, in which there is no indication in the control flow that they exist and you have to go to another screen to see what they are doing.
It's much more clear to use the control flow to direct errors. Any arrow from any task or container can be double clicked and configured. Change the constraint option to value=Failure to make the arrow go red.

executeOfflineCommand skips a command while executing from storage on Android

I have to execute "Start" and "Finish" Commands in the Sequential Order in my program and synchronize everything at the end. So I'm inserting the Offline commands in the order first and assuming they will execute in the same order. I'm using "List" with "Iterator" for this.
Problem here is: Finish Command will be missed execution in some strange scenarios in the middle and "start" commands will execute next to each other and sending all wrong data and mapped it in a wrong way.
As action will get ID when command executes at the server, I'm keeping tempory id's to map the offline commands in storage(localID). Instaead of List if I use anyother collection will this gets any better? It is hard to reproducing this on simulator. Please review both scenarios and advise where can this approaches go wrong. Thanks
I will add the OfflineCommands into the List and save in the Storage. After that user can perform delete delete operation in the App so that I will retrieve the list and remove the commands which got deleted from storage so now I have filtered list.
Don't synchronize.
That's nearly always a mistake in Codename One. Your code deals with the UI so it should be on the EDT and Display.getInstance().isEDT() should be true.
My guess is that one of the commands in the middle uses one of the following invokeAndBlock() derivatives:
addToQueueAndWait
Modal dialogs
Which triggers a second round of synchronization to run.
You can trace that by reproducing the issue and checking which command in the list is specifically there at each time. Then fix that command so it doesn't block in this way.
Another approach to fixing it is to remove the list immediately when you start processing which will prevent a duplicate execution of commands.

Runnig N times the simulation in anylogic

In my anylogic Project, I want to terminate my execution and run the simulation for N times. in each of the simulation I store my output in an excel file which depends on the run count.
Instead of stopping and running by my click, I want to do it automatically. How can I do that?
I try to use an event and write by while loop (myparm<=N) and in loop I wrote getEngine().run, but it didn't work!
if it is possible please help me.
Thanks
Below is an overview of a methodology of how you can do it using the existing simulation framework used by AnyLogic
You need to make use of the simulation setup in order to run multiple runs of the model and save the output. My suggested setup will be the following:
Have a button on your Simulation Experiment page (The first page you see when running the model) that you will use to start off the multiple model runs. In here you set the engine to not run in real time mode by using
getEngine().setRealTimeMode(false);
you might also want to set the initial seed and some other model parameters that you might also want to change and perhaps save after model execution. When you have setup the model the way you want use run() to start running the model.
Now under the Simulation Experiment setup page under the 'Java actions' section you need to specify what the model must do after it finished running the model. In the 'After simulation run' section write some code to save the data from the model into your Excel files. To access variables and objects from the model use root, e.g.
saveSomeData(root.myDataset);
where saveSomeData is a function on the Simulation page to save my data set found on the model, called myDataset, to an Excel file. It would be great to also save the seed and the specific parameters, if you changed any, to the Excel file for future reference.
Once you have saved the data output from the model you can specify a new seed and perhaps change parameters again and then call the run() again to run the model for another iteration. When the model has finished running it will again call the 'After simulation run' code here, so do put a stop condition otherwise it will just continue running one iteration after the other. You can access the number of model runs by using
getEngine().getRunCount()
Also, your model needs to have some stop condition, otherwise once it starts running it will never stop. You can specify this in the Simulation Experiment page under the 'Model time' section or programatically in your model using
finishSimulation();
In order to run the model cyclically, please use the following code in the Action field of a timeout triggered event or On destroy field of the top-level agent:
new Thread(){
public void run(){
// stops the model
getExperiment().stop();
try {
// delay
this.sleep(1000);
} catch(Exception e) {};
// runs it again
((Simulation) getExperiment()).button.action();
}
}.start();
The model results should be written to the Excel file before executing this code.
As Jaco-Ben suggested, you can specify getEngine().getRunCount() as condition of restarting the Simulation experiment.

Running a script component before writing data to a flat file in SSIS

In my SSIS package I need to modify the flat file name that will get creted at the last step of my data flow execution. Currently, I need to transit input data though the Script Component + do a code modifications to a variable that will form a flat file component connection string. The actual data set that should be written is generated by Merge Join component and transiting it through the script component jsut to call one user variable adjustment seems like and overhead.
What is the best practice for an aforemention situation?
If the file name doesn't depend on anything in the data, then I would use a Script Task in the control flow rather than a Script Component in the data flow to set the value.
If the file name does depend on something in the data, a Script Component is probably the best way to get that information; however, the Script Component cannot update any ReadWrite variables outside of the PostExecute method (which will not happen until all the input rows have been processed); this means that the variable changes will not be reflected in the output file's name. In this case, I'd suggest using a File System Task to rename the file after the data flow completes.
Personally I would use a rename DOS command afterwards. Export to a fixed filename and rename it afterwards. To me it's simpler.

Resources