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

  • epivaral

    Old Hand

    Points: 383

    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

    SSCrazy Eights

    Points: 9716

    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

    SSC Rookie

    Points: 27

    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

    SSCrazy Eights

    Points: 9716

    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

    SSC Eights!

    Points: 908

    Nice example

  • BrianWS1O

    SSC Rookie

    Points: 29

    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.

  • epivaral

    Old Hand

    Points: 383

    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

  • epivaral

    Old Hand

    Points: 383

    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

    SSC Rookie

    Points: 46

    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

  • epivaral

    Old Hand

    Points: 383

    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

    SSC Rookie

    Points: 46

    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.

Viewing 11 posts - 1 through 11 (of 11 total)

You must be logged in to reply to this topic. Login to reply