c# - SSIS - Move Excel File with OLEDB Connection to Archive -


i've created connection using microsoft office 12.0 access database engine ole db provider excel schema loop through sheets in excel file demonstrated in question how loop through excel files , load them database using ssis package?

and using foreach ado.net schema rowset enumerator loop through excel files.

everything working fine now, after importing data excel, wanted move file archive folder. , tried using file system task, error as

[file system task] error: error occurred following error message: "the process cannot access file because being used process.".

and tried script task link. getting error , couldn't solve error i've got 0 knowledge on c#.

below error i've got when tried move files using script task.

at system.runtimemethodhandle.invokemethod(object target, object[] arguments, signature sig, boolean constructor) @ system.reflection.runtimemethodinfo.unsafeinvokeinternal(object obj, object[] parameters, object[] arguments) @ system.reflection.runtimemethodinfo.invoke(object obj, bindingflags invokeattr, binder binder, object[] parameters, cultureinfo culture) @ system.runtimetype.invokemember(string name, bindingflags bindingflags, binder binder, object target, object[] providedargs, parametermodifier[] modifiers, cultureinfo culture, string[] namedparams) @ microsoft.sqlserver.dts.tasks.scripttask.vstataskscriptingengine.executescript().


update:

here's complete code i'm trying move files.

if add breakpoint @ enum scriptresults, don't popup , task gets completed , file been moved archive, if don't add breakpoint in c# code, pop , file not moved archive.

#region namespaces using system; using system.data; using microsoft.sqlserver.dts.runtime; using system.windows.forms; using system.io; #endregion  namespace st_9fc6ad7db45c4a7bb49f303680f789ef {     [microsoft.sqlserver.dts.tasks.scripttask.ssisscripttaskentrypointattribute] public partial class scriptmain :     microsoft.sqlserver.dts.tasks.scripttask.vstartscriptobjectmodelbase     {         public void main()         {             directoryinfo di = new     directoryinfo(dts.variables["splitskill_folderpath"].value.tostring());              fileinfo[] fi = di.getfiles("*.xlsx");             string filename = fi[0].name;              string sourcefilename = filename;             string destinationfile = @"d:\flipkart\data\split     skill\archive\" + sourcefilename;             string sourcefile = @"d:\flipkart\data\split skill\" +     sourcefilename;              if (file.exists(destinationfile))                 file.delete(destinationfile);             // move file or folder new location:             system.io.file.move(sourcefile, destinationfile);              dts.taskresult = (int)scriptresults.success;         }          #region scriptresults declaration         enum scriptresults         {             success = microsoft.sqlserver.dts.runtime.dtsexecresult.success,             failure = microsoft.sqlserver.dts.runtime.dtsexecresult.failure         };         #endregion      } } 

as far understand, think have task looping through sheets , looping through files. have 2 tasks inside foreach loop. try making copy of file inside foreach loop system task

for executable

c:\windows\system32\cmd.exe 

and arguments soemthing like

c copy "c:\xxx\abc\\destination_template.accdb" "c:\xxx\abc\\destination_template.accdb"destination_template - kopie.accdb" 

then create file system task moves copy archive. should trick (maybe not best approach should work)


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -