Send Email as attachment then delete - ssis

I have an SSIS package where I am generating a file and sending it to a user, that works all well. however, they want the date in the file name, and I don't want to have a bunch of old daily files sitting in my directory, so I try to delete the file after sending (all of this is done is a script task).
System.IO.File.Delete(DestinationName);
Now, the problem is, I get an error saying it can't delete because the file is in use by another process (the sending of the email) so I thought to make it wait a bit:
//wait a minute before deleting
System.Threading.Thread.Sleep(60000);
System.IO.File.Delete(DestinationName);
By this time I have recieved the email, however, the process is still holding on to the file. How do I get the email to let go? Do i need to put this in its own Script Task?
Thanks

Related

adding text to an xls file with bash script

I'm trying to understand if it's possible to write to an xls file with a bash script. Situation is outlined below.
I have a cronjob that runs every monday and generates an xls and emails to my client. This xls is filled with data from a MySQL DB. when the report is empty and the client attempts to open it, it shows as corrupt. Originally I addressed this issue by excluding empty files from the email with an if statement. However, the constraint is that all 4 reports much reach the client - empty or not.
So my question is, can I simply add a row of text at the top with a bash script so the file never "empty"? I'm not an expert in bash scripting by any means, so feedback here would be great. thanks!
Tony
I'm not aware of any pure bash implementation for writing XLS files. There are solutions in other languages such as Perl, Python, or PHP. If you think outside the box there is another option available to you. You mentioned that you currently use an if statement to not attach empty files. Create a blank spreadsheet in a program like MS Excel, optionally enter some text in A1 like "No records", save it, and transfer that to a known location on the server that runs the cronjob. Rather that skipping the attachment, whenever you detect an empty file in your if statement just attach the blank "No records" template XLS file. You may need to copy the template to a temporary location before attaching if you need to rename the file.

How to BULK INSERT files that change name every day?

I have a folder that is static with a daily txt file that goes into the folder. The file name is the date. If the file name has the same name every day, everything works. Is there a way I can have my script pull any txt file in the folder? (Note, file comes in, get's processed and then I have an automatic transfer that moves the file after it has been inserted to a processed folder). So there will only be one file at a time in the folder. I hope that makes sense.
Here is the script for the bulk insert:
Bulk Insert Mydata.dbo.cust_adj
From 'C:\MyData\FlatFiles\UnprocessedAdjReport\importformat.txt'
With
(
FieldTerminator= '|',
Rowterminator= '\n'
)
Go
(I've got this saved as a stored procedure btw)
So "importformat" is just the name I used while setting up my scripts, going forward it will be in bb-yyyy-mmdd-hhmmnnnn.txt, as soon as the file is inserted, I move the file from the unprocessed folder to the processed folder. There will only be the one file each day.
If anyone has any advice or assistance with this, I would greatly appreciate it.
See the link it may be what you are looking for:
http://www.kodyaz.com/articles/how-to-extract-filename-from-path-using-sql-functions.aspx
Or
http://sqljourney.wordpress.com/2010/06/08/get-list-of-files-from-a-windows-directory-to-sql-server/
Or maybe
http://www.codeproject.com/Articles/38850/An-Easy-Way-to-Get-a-File-Name-or-a-File-Extension
HTH

Force delete a file using SSIS on a network location

I am facing a problem while deleting a file on a network location using SSIS, since its a zip file, contains monthly SQL Database backup file, so I need to delete the last month file before copying current month file.
May be there is some app which were using this file, I am not sure, but I wanna get rid of this file, so that I can copy new file.
Thanks
Use a file task and you should be able to delete pretty much anything on any location as long as you have the rights to do so.

How to get a notification when user deletes a file?

Is there a way to get a notification (like a state with "delete" action and file id) when the user deletes a file of my app on drive?
Thanks,
Daniel
There is no notification right now, but if you look at the Changes for an account, there will be an entry with deleted field set to true with the File ID for the deleted file.
I don't have a knowleges in Google-drive-sdk, but I have already create a similar function in php:
With a CRON ( php script running in background task) I list files in my folder, and I compare with a database ( I add a filename, size file, in database when user add file) , if file exist in database, and not exist in my list, user delete this file and I want send a notification...
until a person expert on "Google-drive" you find a solution, I hope mine will come in handy.

How can I add file locations to a database after they are uploaded using a Perl CGI script?

I have a CGI program I have written using Perl. One of its functions is to upload pics to the server.
All of it is working well, including adding all kinds of info to a MySQL db. My question is: How can I get the uploaded pic files location and names added to the db?
I would rather that instead of changing the script to actually upload the pics to the db. I have heard horror stories of uploading binary files to databases.
Since I am new to all of this, I am at a loss. Have tried doing some research and web searches for 3 weeks now with no luck. Any suggestions or answers would be greatly appreciated. I would really hate to have to manually add all the locations/names to the db.
I am using: a Perl CGI script, MySQL db, Linux server and the files are being uploaded to the server. I AM NOT looking to add the actual files to the db. Just their location(s).
It sounds like you have your method complete where you take the upload, make it a string and toss it unto mysql similar to reading file in as a string. However since your given a filehandle versus a filename to read by CGI. You are wondering where that file actually is.
If your using CGI.pm, the upload, uploadInfo, the param for the upload, and upload private files will help you deal with the upload file sources. Where they are stashed after the remote client and the CGI are done isn't permanent usually and a minimum is volatile.
You've got a bunch of uploaded files that need to be added to the db? Should be trivial to dash off a one-off script to loop through all the files and insert the details into the DB. If they're all in one spot, then a simple opendir()/readdir() type loop would catch them all, otherwise you can make a list of file paths to loop over and loop over that.
If you've talking about recording new uploads in the server, then it would be something along these lines:
user uploads file to server
script extracts any wanted/needed info from the file (name, size, mime-type, checksums, etc...)
start database transaction
insert file info into database
retrieve ID of new record
move uploaded file to final resting place, using the ID as its filename
if everything goes file, commit the transaction
Using the ID as the filename solves the worries of filename collisions and new uploads overwriting previous ones. And if you store the uploads somewhere outside of the site's webroot, then the only access to the files will be via your scripts, providing you with complete control over downloads.