September 12, 2014 at 8:36 am
Hi I am receiving 1 csv file daily. The schema is static and the same for each file. I have created a table with the same schema as the csv.
Is it possible to create a SSIS job which
1. Monitors the directory or runs at a particular time
2. imports the csv data into the table
3. moves the file once it has been processed to an archive directory.
Any good links to a tuturial would be appreciated. I have tried a couple but they are not basic enough for a newbee:-P
Thanks in advance
September 12, 2014 at 9:11 am
G-Force (9/12/2014)
Hi I am receiving 1 csv file daily. The schema is static and the same for each file. I have created a table with the same schema as the csv.Is it possible to create a SSIS job which
1. Monitors the directory or runs at a particular time
2. imports the csv data into the table
3. moves the file once it has been processed to an archive directory.
Any good links to a tuturial would be appreciated. I have tried a couple but they are not basic enough for a newbee:-P
Thanks in advance
What do the filenames look like?
--Jeff Moden
Change is inevitable... Change for the better is not.
September 13, 2014 at 5:32 am
The file name is todays date time stamp
YYYYMMDDhhmmss.csv
Thanks
G
September 13, 2014 at 8:30 am
G-Force (9/12/2014)
Hi I am receiving 1 csv file daily. The schema is static and the same for each file. I have created a table with the same schema as the csv.Is it possible to create a SSIS job which
1. Monitors the directory or runs at a particular time
2. imports the csv data into the table
3. moves the file once it has been processed to an archive directory.
Any good links to a tuturial would be appreciated. I have tried a couple but they are not basic enough for a newbee:-P
Thanks in advance
Quick thought, this is straight forward in SSIS, suggest you start by reading through Stairway to Integration Services[/url].
😎
September 15, 2014 at 9:55 am
Apologies... really got hammered by work-work.
Are you all set now?
Just as a bit of a sidebar, this is also pretty easy using only T-SQL. If you'd rather do that than work this problem in SSIS, let us know.
--Jeff Moden
Change is inevitable... Change for the better is not.
September 16, 2014 at 1:36 am
Hi Jeff
Still trying to find the dummies guide 🙂 . Is there anywhere you can point me to on how to do it in TSQL ?
Any help gratefully received.
Thanks
G
September 16, 2014 at 10:14 am
G-Force (9/16/2014)
Hi JeffStill trying to find the dummies guide 🙂 . Is there anywhere you can point me to on how to do it in TSQL ?
Any help gratefully received.
Thanks
G
hi...these may help you
http://www.mssqltips.com/sqlservertip/2874/loop-through-flat-files-in-sql-server-integration-services......shows you how to move files within SSIS
http://sqlblog.com/blogs/jamie_thomson/archive/2010/03/31/filenamecolumnname-property-flat-file-source-adapter-ssis-nugget.aspx ...usefull info for recording the original filename for the import
________________________________________________________________
you can lead a user to data....but you cannot make them think
and remember....every day is a school day
September 16, 2014 at 10:53 am
G-Force (9/16/2014)
Hi JeffStill trying to find the dummies guide 🙂 . Is there anywhere you can point me to on how to do it in TSQL ?
Any help gratefully received.
Thanks
G
The basics are to determine if the file is there and then import it using BULK INSERT. I'll see if I can whip up an example for you tonight. In the mean time, can you post the CREATE TABLE statement for the "target" table and (if there's no personal or company private information), attach a file with at least the first 10 lines of data in it (including any headers, etc).
--Jeff Moden
Change is inevitable... Change for the better is not.
September 17, 2014 at 1:15 am
SSIS can also do this well along with SQL Agent to run the SSIS package. Either waiting for a file to appear in a folder or running at specified times is possible.
We deal with over 500 csv format files every day in both these ways.
I use a script task in SSIS to see if a file is arriving as some of ours are quite large and wait until it is fully available then for zip files,a For Each loop with an execute command task to unzip it into a folder with the 7zip tool before processing the csv files into the staging and then main reporting database and a File System task to move the processed files to an archive directory (script task if you want to create a dated one).
Package logging and error handling ensure you know when anything goes wrong.
September 17, 2014 at 8:33 am
P Jones (9/17/2014)
...and wait until it is fully available ....
I'm curious. What are you using to determine that a file is done being written to and is ready for consumption? (other than a popup thermometer or fork :-P)
--Jeff Moden
Change is inevitable... Change for the better is not.
September 19, 2014 at 12:59 am
Jeff Moden (9/17/2014)
P Jones (9/17/2014)
...and wait until it is fully available ....I'm curious. What are you using to determine that a file is done being written to and is ready for consumption? (other than a popup thermometer or fork :-P)
Stick a finger in the air and see which way the wind's blowing. 😀
Actualy a bit of vb script in a script task as the ftp comining in takes about 20 minutes to transfer a big zip file and the file shows as existing from the start but is locked by the ftp until fully done. I probably found the idea somewhere by Googling but it was a couple or three years ago. And I do lots of package logging so I can just run a quick query as a daily check to see package errors.
While (FileLocked)
Try
' Check if the file isn't locked by an other process by opening
' the file. If it succeeds, set variable to false and close stream
fs = New FileStream(fnvar, FileMode.Open)
' No error so it is not locked
logmsg = "File not locked: " & fnvar
Dts.Log(logmsg, 0, b)
FileLocked = False
' Close the file and exit the Script Task
fs.Close()
Dts.TaskResult = ScriptResults.Success
Catch ex As IOException
' If opening fails, it's probably locked by an other process. This is the exact message:
' System.IO.IOException: The process cannot access the file 'D:\example.csv' because it is being used by another process.
' Log the locked status (once)
If (ShowLockWarning) Then
logmsg = "File locked: " & fnvar & " " & ex.Message
Dts.Log(logmsg, 0, b)
End If
ShowLockWarning = False
' Wait two seconds before rechecking unless we've done 30 mins
If DateDiff(DateInterval.Minute, Date.Now, starttime) < 30 Then
Thread.Sleep(2000)
Else
logmsg = "Given up after waiting 30 mins. File locked: " & fnvar & " " & ex.Message
Dts.Log(logmsg, 0, b)
Dts.TaskResult = ScriptResults.Failure
Exit While
End If
Catch ex As Exception
' Catch other unexpected errors and break the while loop
logmsg = "Unexpected error: " & fnvar & " " & ex.Message
Dts.Log(logmsg, 0, b)
Dts.TaskResult = ScriptResults.Failure
Exit While
End Try
End While
September 19, 2014 at 8:35 am
P Jones (9/19/2014)
Jeff Moden (9/17/2014)
P Jones (9/17/2014)
...and wait until it is fully available ....I'm curious. What are you using to determine that a file is done being written to and is ready for consumption? (other than a popup thermometer or fork :-P)
Stick a finger in the air and see which way the wind's blowing. 😀
Actualy a bit of vb script in a script task as the ftp comining in takes about 20 minutes to transfer a big zip file and the file shows as existing from the start but is locked by the ftp until fully done. I probably found the idea somewhere by Googling but it was a couple or three years ago. And I do lots of package logging so I can just run a quick query as a daily check to see package errors.
While (FileLocked)
Try
' Check if the file isn't locked by an other process by opening
' the file. If it succeeds, set variable to false and close stream
fs = New FileStream(fnvar, FileMode.Open)
' No error so it is not locked
logmsg = "File not locked: " & fnvar
Dts.Log(logmsg, 0, b)
FileLocked = False
' Close the file and exit the Script Task
fs.Close()
Dts.TaskResult = ScriptResults.Success
Catch ex As IOException
' If opening fails, it's probably locked by an other process. This is the exact message:
' System.IO.IOException: The process cannot access the file 'D:\example.csv' because it is being used by another process.
' Log the locked status (once)
If (ShowLockWarning) Then
logmsg = "File locked: " & fnvar & " " & ex.Message
Dts.Log(logmsg, 0, b)
End If
ShowLockWarning = False
' Wait two seconds before rechecking unless we've done 30 mins
If DateDiff(DateInterval.Minute, Date.Now, starttime) < 30 Then
Thread.Sleep(2000)
Else
logmsg = "Given up after waiting 30 mins. File locked: " & fnvar & " " & ex.Message
Dts.Log(logmsg, 0, b)
Dts.TaskResult = ScriptResults.Failure
Exit While
End If
Catch ex As Exception
' Catch other unexpected errors and break the while loop
logmsg = "Unexpected error: " & fnvar & " " & ex.Message
Dts.Log(logmsg, 0, b)
Dts.TaskResult = ScriptResults.Failure
Exit While
End Try
End While
And it's even got some documentation built into it! Thank you for taking the time to post that. 🙂
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 12 posts - 1 through 11 (of 11 total)
You must be logged in to reply to this topic. Login to reply