.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
satyapriyanayak
kelly456
Post New Web Links

foreach loop - delete file task

Posted By:      Posted Date: November 04, 2010    Points: 0   Category :Sql Server
 

i have ado enumerator on foreach loop and one of the variable contains the file name. following are the task which get executed in for each loop but i'm getting error on delete file task

1. Run a script to create pdf file from ssrs (using filename and path in ado enumerator). Working great.

2. Send email with attached of above pdf file (working great)

3. Now in 3rd step, i want to delete the file, so used file system task and delete file . i'm getting following error

[File System Task] Error: An error occurred with the following error message: "The process cannot access the file 'p:\information technology\report output to send\eft\0000023744-EF_DEN1_10-29-10_EFT.pdf' because it is being used by another process.".

I'm not sure what is using the file that it is not letting me delete the file.

Any clue?


mark it as answer if it answered your question :)


View Complete Post


More Related Resource Links

ForEach Loop reads next file when child task fails

  

We have a ForEach loop that reads over a list of files in a directory.  We are placing the current file name into a parent variable and passing it into children packages through the Parent Package Variables configuration.  We have attached a Execute Package task for the ForEach loop Failure constraint.  The package is an exception handler that moves the current file (set in the ForEach loop variable mapping) to a failure folder.

The issue is that when the exception handler is called, the file name being passed in is the next file in the directory, not the file currently being processed.  Is this due to read ahead by the ForEach loop?  I pass this variable exactly the same way to child packages within the ForEach loop and it works fine.  It is just when I pass the variable to the constraint path from the ForEach loop that changes the value of the variable.  Is this because the exception handler sits outside of the loop container?

Thanks for your help.

Scott 


Foreach Loop Container & File System Task to copy files from target server to source server

  

A one-off shot at using, SSIS, I appear to be missing something. 

From what I have read here, the Foreach Loop Container in which a File System Task has been placed is how one copies files contained in a source server folder to a folder on a target server.  I have defined Source and Destination pkg variables using UNC \\servername\aharedfolder and a FileName variable that is empty.  My impression is that this is suppose to iterate through and copies all files in the source folder to the target.  I only get the first file copied.

In the FLC Collection section  I am using the Foreach File Enumerator under which I have the Folder as \\servername\sharedfolder and files as *.* .  I am not using Expressions.  The Variables Mapping reference my FileName variable.

In the FST, I both path variables set to True and reference the destination and source variables described above.  Operation is Copy File.

I appears that I need to pass a list of the source folder file names to the FileName variable, rather than some built-in logic grabbing a files in the source folder.  Is a passed filename list what I am missing?


SSIS 2005 - Foreach loop container - Stopping the loop after processing X number of file?

  
I need to stop the Foreach loop container from processing more files in the folder than desired. Scenario:  If I only want 1 files processed, i need to stop the loop after it finds 1 file.  No matter what the contraints or tests or variables I set, the loop processes all the files in the folder.  This is bad because I need the value of the 1st mapped variable and not the last one it finds. I have tried counting records and setting variables used in the contraints but to no avail  Nothing seems to stop the loop. Please advise

How to go to next iteration of ForEach Loop container on task failure

  
I'm using a ForEach Loop container to iterate through a set of files and import/validate the data.  Within each loop, the first thing that happens is that I fill a variable from a table and then use a script task to make sure that the rest of the package should be run for this particular file.  If it should continue, I set Dts.TaskResult = Dts.Results.Success, and if it shouldn't, I set it to Dts.Results.Failure.  My question is, how do I get it to exit the current iteration of the loop and continue to the next iteration?  The way it is now, the package just stops completely.  I set the FailPackageOnFailure property to False for the script task, but that doesn't make a difference.  I also tried pointing a failure precedence contstraint bacl to the loop container, but that's not allowed.  How can I make it just continue in the loop?   Thanks.

SQL 2005, mainteance clean up task didn't delete a manual bak file with different format name, is i

  
I have a manual full backup, its name is in different format than scheduled dbname_date....bak, the clean up didn't delete it, is it normal?

Programmatically delete a .webpart file from wpcatalogs folder from an IIS website

  

We are using a third party wsp in our solution which directly adds the web parts into the web application store rather than the web part gallery(References to them are present in IIS site's wpcatalog directory). We want to remove these web part files so that the users will not be able to add these web parts to pages directly. Or any other modification so that users will not be able to add these directly. Is there a way we can do this programmatically?


Receive/Delete Multiple FTP Files based on condition using SCRIPT(VB) TASK

  
I am trying to receive and delete multiple FTP files from a remote FTP server using Script task Below is the code   Dim FTPConnMgr As ConnectionManager FTPConnMgr = Dts.Connections("FTP Connection Manager") Dim FTPClientConn As FtpClientConnection = New FtpClientConnection(FTPConnMgr.AcquireConnection(Nothing)) Dim FileTimeStampNew As String = "20100913021807" Dim remoteFileNames(0) As String remoteFileNames(0) = Dts.Variables("FtpRemoteDirectory").Value & "*" & FileTimeStampNew & ".*" 'Below hardcoded FileName works good. But the problem is there are lots of file in the FTP folder that I dont want to receive 'remoteFileNames(0) = Dts.Variables("FtpRemoteDirectory").Value & "Company_alpha_Full_20100913021807.xml" Dim localPath As String = Dts.Variables("FtpLocalDirectory").Value FTPClientConn.Connect() FTPClientConn.ReceiveFiles(remoteFileNames, localPath, False, False) FTPClientConn.Close() Dts.TaskResult = ScriptResults.Success End Sub End Class If i specifically mention the RemotefileNames this works fine but, when I say *.* it executes succefully but doesn't receives the file. Please advice how to receive multiple file based on a variable BR, AWM

Error on 23rd Loop of Foreach

  
Hi, I have a MAster Package callling 8 Dimension Package and 5 fact table packages. Fact table Packages are in for eachloop. They have to loop 24 times during FirstRun Each fact table load more than 500000 rows in every loop, and out of 5, two package loads more than million rows in every loop. I got the following error message when the package was looping for the 23rd time. One of the five Fact table package failed with following error DTS primeoutput failed returned error code 0xC02020C4 SSIS Error Code DTS_E_PRIMEOUTPUTFAILED. The PrimeOutput method on component "Staging Table "(1) returned error code 0xC02020C4. The component returned a failure code when the pipeline engine called PrimeOutput(). The meaning of the failure code is defined by the component, but the error is fatal and the pipeline stopped executing. There may be error messages posted before this with more information about the failure. After when I ran package explicitly, it ran well Please help on what to be done to avoid this error and what does this error mean?. I am Using SQL Server 2008, i5 Processor, 3.42GB RAm, DefaultBufferMaxRows = 10000 and Default BufferSize 10MB, EngineTHread=10 Thanks, Anuja

ForEach Loop Container Configuration Question

  
So here is my question/situation. I have a table that contains a list of all of our servers/instances for my organization. I have a script that I'd like to execute against all of the servers in that list and I was thinking that I should be able to use this container to pull the name/instance from the table, execute the script, store the results in a local table. However, I'm not quite sure on how to attack this meaning not sure which configuration that I would need to use to get me going down the right direction. I've looked around and found alot of documentation on how to enumerate multiple files and folders, but nothing really for what I'm trying to do. Any help or direction would be greatly appreciated.Big Ern

Using Foreach loop Container in SSIS 2005 package and scheduling the package using SQL job on 64-bit

  
I've an SSIS package 2005 which uses a for each loop container, this package runs fine when I run it on the local machine . My server is 64 bit SQL 2005 and I 've successfully deployed my package on the server both to the File system and SQL server. I've also set Run64bitruntime to false in my pacakge. Now I need schedule the package using SQL job. Since Microsoft Jet Provider 4.0 is not available for 64 bit, I had to write script to schedule the package. Here is my script. declare   @ssisstr varchar(8000) declare @returncode int set   @ssisstr = 'dtexec /sq Package1 /DE 123' EXEC   @returncode = xp_cmdshell @ssisstr select   @returncode I'm getting the following error when I execute the job. Could not load package "Package1" because of error 0xC0010014. Description: One or more error occurred. There should be more specific errors preceding this one that explains the details of the errors. This message is used as a return value from functions that encounter errors. I'm getting the same error if I run this from commandline. Any help would be really appreciated. Thanks in advance. PARC

How to delete an image file assigned to a PictureBox xontrol ?

  
In a Windows form application, some image files are assigned to PictureBox controls. I am trying to delete those image files. The first approach [1] with "Image.FromFile" gives an error message of "Another process is using this image file", although "Image.Dispose()" is executed. The second approach [2] using "Image.FromStream" results (X) images for PictureBoxes and Buttons, if "fs.Close()" is inclided. Without "fs.Close()", it gives the same error message of "Another process is using...". How can I display images properly and delete those images files ? Thanks [1] pictureBoxSelected.Image = Image.FromFile(@actualImage); . . . pictureBoxSelected.Image.Dispose(); pictureBoxSelected.Image = Image.FromFile(@tempImage);                                                if (System.IO.File.Exists(actualImage) == true) {     System.IO.File.Delete(actualImage); } [2] FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read); pictureBox.Image = System.Drawing.Image.FromStream(fs); fs.Close();

Foreach Loop Container.ForEachEnumerator.Properties[FileSpec] Exception -This occurs when an attempt

  
I run into the following 2 exceptions when I execute a package on SQL Server 2005 64 bit machine. The package fails when SQL Server version is 9.0.3310 which is a production box. I have tested it on 3 others development boxes with SQL version 9.0.1399, 9.0.3315 & 9.0.4053 and the package executes fine. I am unable to make a determination if this issue is related to SQL versions or a bug in the package design. I would like to understand the exception better before I request an SP3 & patches installed to upgrade it to version 9.0.4053 on the production box. I have scheduled jobs to run these packages and we are trying to locate Excel files on a drive using For Each Loop Enumerator. The packages are configured to use configuration files. Please note the destination directory does have the Excel files we are looking for. Source: Well_Test_Package Description: The package path referenced an object that cannot be found: "\Package\Daily Alloc Spread Sheet Foreach Loop Container.ForEachEnumerator.Properties[Directory]". This occurs when an attempt is made to resolve a package path to an object that cannot be found.  End Warning  Warning: 2010-08-31 00:41:13.66     Code: 0x80012017     Source: Well_Test_Package      Description: The package path referenced an object that ca

SSIS FOR each loop to load 1 file after other into database for particaular folder

  
HI I am using ssis 2008,i have folder in which i have 10 excel file.i wont to load them one after other in data  base I have created a Dataflow task that load one file into database.i have inserted this dataflow task into For each loop and in For each loop i have give that folder path and *.XLSX  and in variable mapping i have created one variable  which i have passed in Database destination connecion string (properties->expression) but still i get error "cannot acquire connection from connection manager" please guide me or provide me with some reference so that i cud load file from folder into database one after other

How to delete a file which was accessed by other process ?

  
Does Windows have a "unlock object" method in order to delete a file which is being used by another process ? Thanks
Categories: 
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend