SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


SSIS Basics: Bulk-Import various text files into a table


SSIS Basics: Bulk-Import various text files into a table

Author
Message
Eduardo Pivaral
Eduardo Pivaral
Valued Member
Valued Member (71 reputation)Valued Member (71 reputation)Valued Member (71 reputation)Valued Member (71 reputation)Valued Member (71 reputation)Valued Member (71 reputation)Valued Member (71 reputation)Valued Member (71 reputation)

Group: General Forum Members
Points: 71 Visits: 63
Comments posted to this topic are about the item SSIS Basics: Bulk-Import various text files into a table

MCSE, MCSA SQL Server Database Developer/Administrator


richardmgreen1
richardmgreen1
SSCertifiable
SSCertifiable (7.7K reputation)SSCertifiable (7.7K reputation)SSCertifiable (7.7K reputation)SSCertifiable (7.7K reputation)SSCertifiable (7.7K reputation)SSCertifiable (7.7K reputation)SSCertifiable (7.7K reputation)SSCertifiable (7.7K reputation)

Group: General Forum Members
Points: 7727 Visits: 1458
We do something similar with one of our imports.
We have to import 160 (or so) files into separate tables.

We set it up so that we build the tables first and then use a similar looping technique to go through the file list.

We've also managed to get it to import several files simultaneously.

We can now load 300MB of .CSV files (all with different layouts) in around 20 minutes.
bhoelzer
bhoelzer
Forum Newbie
Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)

Group: General Forum Members
Points: 9 Visits: 101
How do you handle the situation where you have some quoted strings, because of embedded commas, and some normal strings?

For example:

string1,1,2,3
"string, 2",4,5,6
string3,7,8,9
richardmgreen1
richardmgreen1
SSCertifiable
SSCertifiable (7.7K reputation)SSCertifiable (7.7K reputation)SSCertifiable (7.7K reputation)SSCertifiable (7.7K reputation)SSCertifiable (7.7K reputation)SSCertifiable (7.7K reputation)SSCertifiable (7.7K reputation)SSCertifiable (7.7K reputation)

Group: General Forum Members
Points: 7727 Visits: 1458
We did have that issue, but we got round it by setting the delimiter to quotes in one of the settings (can't remember which one without checking).

It's working so far as it seems to ignore the delimiter if it doesn't exist.
Bruce Dow
Bruce Dow
SSC Eights!
SSC Eights! (809 reputation)SSC Eights! (809 reputation)SSC Eights! (809 reputation)SSC Eights! (809 reputation)SSC Eights! (809 reputation)SSC Eights! (809 reputation)SSC Eights! (809 reputation)SSC Eights! (809 reputation)

Group: General Forum Members
Points: 809 Visits: 235
Nice example
Brian Battles
Brian Battles
Forum Newbie
Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)

Group: General Forum Members
Points: 7 Visits: 7
Mine died at Execute Package. It said:

Cannot bulk load because the file (xxx) could not be opened. Operating system error code 5(Access is denied.).

But it imports the file just fine if I use the Import Wizard to create a DTSX file.
Eduardo Pivaral
Eduardo Pivaral
Valued Member
Valued Member (71 reputation)Valued Member (71 reputation)Valued Member (71 reputation)Valued Member (71 reputation)Valued Member (71 reputation)Valued Member (71 reputation)Valued Member (71 reputation)Valued Member (71 reputation)

Group: General Forum Members
Points: 71 Visits: 63
bhoelzer - Tuesday, October 9, 2018 5:03 AM
How do you handle the situation where you have some quoted strings, because of embedded commas, and some normal strings?

For example:

string1,1,2,3
"string, 2",4,5,6
string3,7,8,9


Hi Bhoelzer, the bulk insert task is designed for performance, hence there is no way to perform validations with this component, you will have to replace the Bulk Insert Task with a Data Flow Task and perform a data cleansing there (or you can put another step before the bulk insert to format the file).
Hope this helps!

MCSE, MCSA SQL Server Database Developer/Administrator


Eduardo Pivaral
Eduardo Pivaral
Valued Member
Valued Member (71 reputation)Valued Member (71 reputation)Valued Member (71 reputation)Valued Member (71 reputation)Valued Member (71 reputation)Valued Member (71 reputation)Valued Member (71 reputation)Valued Member (71 reputation)

Group: General Forum Members
Points: 71 Visits: 63
BrianWS1O - Tuesday, October 9, 2018 9:32 AM
Mine died at Execute Package. It said:

Cannot bulk load because the file (xxx) could not be opened. Operating system error code 5(Access is denied.).

But it imports the file just fine if I use the Import Wizard to create a DTSX file.

Hi Brian, this is a common issue using windows 7 or some restricted UAC OS, can you give it a try running SSDT as a Local Administrator?


MCSE, MCSA SQL Server Database Developer/Administrator


kducote
kducote
Grasshopper
Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)

Group: General Forum Members
Points: 16 Visits: 23
A much more simple solution than looping is to use the "Multi Flat File Connection" in your Connection Managers. If you right-click in the Connection Managers section and select New Connection it is in the list. You can point it to a directory and wildcard your file name such as *.CSV and then import all the files matching the criteria. The example provided is a much more granular approach and has its merits, but if you are looking to simply import a set of CSV files in one swoop try this alternative.

Kendall
Eduardo Pivaral
Eduardo Pivaral
Valued Member
Valued Member (71 reputation)Valued Member (71 reputation)Valued Member (71 reputation)Valued Member (71 reputation)Valued Member (71 reputation)Valued Member (71 reputation)Valued Member (71 reputation)Valued Member (71 reputation)

Group: General Forum Members
Points: 71 Visits: 63
kducote - Wednesday, October 10, 2018 8:59 AM
A much more simple solution than looping is to use the "Multi Flat File Connection" in your Connection Managers. If you right-click in the Connection Managers section and select New Connection it is in the list. You can point it to a directory and wildcard your file name such as *.CSV and then import all the files matching the criteria. The example provided is a much more granular approach and has its merits, but if you are looking to simply import a set of CSV files in one swoop try this alternative.

Kendall

ohh Thanks Kendall, even when I did not know that method (i learned something new today), my objective was to show how the ForEachLoop Container works, and i tought the bulk insert task is one of the simplest examples i could make to not complicate the tutorial with weird data flow tasks...

but thanks for the tip! i will give it a try!


MCSE, MCSA SQL Server Database Developer/Administrator


kducote
kducote
Grasshopper
Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)

Group: General Forum Members
Points: 16 Visits: 23
epivaral - Wednesday, October 10, 2018 11:01 AM
kducote - Wednesday, October 10, 2018 8:59 AM
A much more simple solution than looping is to use the "Multi Flat File Connection" in your Connection Managers. If you right-click in the Connection Managers section and select New Connection it is in the list. You can point it to a directory and wildcard your file name such as *.CSV and then import all the files matching the criteria. The example provided is a much more granular approach and has its merits, but if you are looking to simply import a set of CSV files in one swoop try this alternative.

Kendall

ohh Thanks Kendall, even when I did not know that method (i learned something new today), my objective was to show how the ForEachLoop Container works, and i tought the bulk insert task is one of the simplest examples i could make to not complicate the tutorial with weird data flow tasks...

but thanks for the tip! i will give it a try!

You did a great job demonstrating the ForEachLoop; In fact I bookmarked the article as "ForEachLoop Example" in my SQL favorites folder. No disrespect or minimization of your article intended and I apologize if it came off as such.

Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum








































































































































































SQLServerCentral


Search