Question : depending upon the file name I have to import the file in SSIS

Hi i am  a sqldeveloper and a total zero in .net .I want to import a txt file to a sql server table .First I have to check if the file exists or not.the file will be stored  in a hardcoded folder example 'C:\text' manually and the file name will be 'name0708.txt' ie the file name will be name and the datastamp only month and day(note the name is hardcoded).tomorrow the file name is name0709.txt.Can some one tell me how to do this with SSIS

Answer : depending upon the file name I have to import the file in SSIS

Not sure which version of SSIS you're using.  2008 supports c# scripting, where 2005 is only vb.net.

Within SSIS:
1.  Add a variable to hold your filename/path.
     (several ways to get to variables - just right click in control flow area and select "Variables")

2.  Add a script task to control flow- you can use VB.net to see if the file exists.  If it does, get the file name and put it in as your variable
http://www.vb-helper.com/howto_net_file_exists.html
http://www.developerdotstar.com/community/node/512  <--write to variables in script task

3.  Add a data flow task to your control area and double click it

4.  Under Data Flow Sources, select a flat file source - double click it and add a new connection manager (just pick a representative test file).

5.  Now under connection managers (at bottom), click on the new text connection manager made in step
4.  Under its properties, see the Expressions area.  Click the "..." to get in to the editor.  Under property, select "ConnectionString".  Under Expression you will select your variable in the the following format: @[User::<<variable name>>]

6.  Now add a destination to your Data Flow and drag your text file source to the destination.  Map columns.

Pretty much it.  You just need a variable to hold the name of your file name (given it changes).  Use the script task to modify your variable.  







Random Solutions  
 
programming4us programming4us