February 23, 2007 at 3:32 pm
Hello,
I have a situation where SQL Server table data needs to be exported to flat files on a daily basis. The flat file name needs to contain the current date at the end of the file name. This would mean that the destination Flat File would have a different name every day.
I imagine that this needs to be done in a script task. If so, are there any examples out there where I can pull SQL Server table data, use FileSystemObject to create the daily file, and then export the data to the file?
Thank you for your help!
CSDunn
February 23, 2007 at 4:14 pm
I don't have a detailed example, but you could just use the text document destination connection object and push your data to a working file. Then follow that up with a script task to rename the file, or stream the file contents into your new file. You could even use a .bat file for the file rename or copy.
February 24, 2007 at 4:47 pm
Thank you for your response. That is actually the process in place now. The problem is, the working file gets locked by some other process. I'm trying to take the working file out of he process, and output the data to a new time stamped text file each time the process runs.
I'm checking with the (singular) user of the output. It could be that I may be able to just output the data into another sql server table, and create a small MS Access ADP for the user, where they could use a date filter to get the data they need.
February 25, 2007 at 3:52 pm
This is 3 step process as follows:
Function Main()
' Initialise variables first
DTSGlobalVariables("FilePath").Value = "\\Server\Directory\FileName." & CStr(Year(Date)) & Right("0" & CStr(Month(Date)), 2) & Right("0" & CStr(Day(Date)), 2)
' Other script continues here
'
'
Main = DTSTaskExecResult_Success
End Function
3. Create a Dynamic Properties Task as follows:
Save the package and run.
If you run the package using the Job, then you need to know the SQL-Agent NT login. This login must have proper access permission to \\Server\Directory if your file path is shared directory. Otherwise your job will fail.
February 26, 2007 at 8:21 am
Also, before changing your existing process, it may be worth finding out who or what is locking the file. Check the virus scanning software on the server. Make sure it is set up to omit the directory where you are dropping the working file. If this is not it, have a server SA help you attempt to identify who/what is locking the file the next time you run into that situation.
February 28, 2007 at 4:12 am
Thank you for your help! I implemented a similar solution with a Dynamic Properties Task, but with a SQL Statement using the string for the file path + GETDATE() (I had an existing connection to a SQL Server).
cdun2
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply