sql server - How to execute SSIS package when a file is arrived at folder -


the requirement execute ssis package, when file arrived @ folder,i not want start package manually .

it not sure file arrival timing ,also files can arrive multiple times .when ever files arrived has load table.i think, solution file watcher task ,still expect start package

the way have done in past infinite loop package called sql server agent, example;

this infinite loop package:

simple package

set 3 variables:

isfileexists - boolean - 0

folderlocation - string - c:\where file put in\

isfileexists boolean - 0

for loop container:

for loop container

set isfileexists variables above.

setup c# script task readonlyvariable user::folderlocation , have following:

 public void main()     {         int filecount = 0;         string[] filestoprocess;         while (filecount == 0)         {             try             {                  system.threading.thread.sleep(10000);                 filestoprocess = system.io.directory.getfiles(dts.variables["folderlocation"].value.tostring(), "*.txt");                 filecount = filestoprocess.length;                  if (filecount != 0)                 {                     (int = 0; < filecount; i++)                     {                         try                         {                              system.io.filestream fs = new system.io.filestream(filestoprocess[i], system.io.filemode.open);                             fs.close();                          }                         catch (system.io.ioexception ex)                         {                             filecount = 0;                             continue;                         }                     }                 }             }             catch (exception ex)             {                 throw ex;             }         }          // todo: add code here         dts.taskresult = (int)scriptresults.success;     } } } 

what keep eye on folder location .txt file, if file not there sleep 10 seconds (you can increase if want). if file exist complete , package execute load package. continue run, next time file dropped in execute load package again.

make sure run foreverloop package sql server agent job run time, have similar package running , has never caused problems.

also make sure input package moves/archives file away drop folder location.


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -