Error Handling with Bulk Insert.

  • Hi all,

    Im currently using bulk insert to import data from a flat file to a table in sql server., the import is fine and work as it should apart from ideally i would like to catch the errors thrown by individual rows from the import, without ending the insert.

    Has anyone any ideas on how to do this?

    Many Thanks,

    Scott

  • Your options are the create a SSIS package that dumps problem rows into an error file or you can use BCP to import and set the max errors to a larger value and have it dump into a file, with ERRORFILE = 'file_name'.

    More info on BCP:

    http://msdn2.microsoft.com/en-us/library/ms188365.aspx

  • Not that it matters, but I really like the BCP method... it's pretty darned fast, too. As Adam mentioned, it call also capture the bad rows in a separate file for rework.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

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

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