|
|
|
SSC Veteran
      
Group: General Forum Members
Last Login: Wednesday, June 05, 2013 7:16 AM
Points: 258,
Visits: 353
|
|
| When using bulk insert and specified errorfile paramter, the error file is being deleted when an error is encountered in the data file. Anyone came across this before?
|
|
|
|
|
Mr or Mrs. 500
      
Group: General Forum Members
Last Login: Monday, September 14, 2009 1:59 PM
Points: 516,
Visits: 425
|
|
| Can you provide syntax that includes the BULK INSERT?
|
|
|
|
|
SSC Veteran
      
Group: General Forum Members
Last Login: Wednesday, June 05, 2013 7:16 AM
Points: 258,
Visits: 353
|
|
bulk insert from "e:\datafile.bcp" WITH (FORMATFILE = 'e:\formatfile.xml', maxerrors=0, errorfile='E:\import_error.txt')
|
|
|
|
|
Mr or Mrs. 500
      
Group: General Forum Members
Last Login: Monday, September 14, 2009 1:59 PM
Points: 516,
Visits: 425
|
|
Using FORMATFILE as per BOL you must meet one of these criterias...
The data file contains greater or fewer columns than the table or view.
The columns are in a different order.
The column delimiters vary.
There are other changes in the data format. Format files are typically created by using the bcp utility and modified with a text editor as needed. For more information, see bcp Utility.
Do you meet these criteria to use FORMATFILE? Just a shot
|
|
|
|
|
SSC Veteran
      
Group: General Forum Members
Last Login: Wednesday, June 05, 2013 7:16 AM
Points: 258,
Visits: 353
|
|
I think you misunderstood, the formatfile matches the table definition. The question is why bulk insert creates an error file and then deletes it from disk once finished running?
For instance imagine a a table with one column that has a data type of decimal (11,2), but one of the rows in the file contains much larger value, such as: 999999999999999999999999999.99999, so this won't fit. Running bulk insert on this row will fail. During the run time of bulk insert command two files are created, but after the transaction is rolled back the file is automatically deleted making it impossible to see what was the error message and which rows it failed on.
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: Yesterday @ 1:29 PM
Points: 2,278,
Visits: 3,011
|
|
This is from BOL
MAXERRORS = max_errors Specifies the maximum number of syntax errors allowed in the data before the bulk-import operation is canceled. Each row that cannot be imported by the bulk-import operation is ignored and counted as one error. If max_errors is not specified, the default is 10.
You have this option set to 0, so you are saying that if an error occurs to cancel the insert. This may delete the file because the insert was canceled with no errors written to disk. Try bumping this this number up. The default is 10.
My blog: http://jahaines.blogspot.com
|
|
|
|
|
SSC Veteran
      
Group: General Forum Members
Last Login: Wednesday, June 05, 2013 7:16 AM
Points: 258,
Visits: 353
|
|
| I did, but it still deletes the file.
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: Yesterday @ 1:29 PM
Points: 2,278,
Visits: 3,011
|
|
Does 'E:\import_error.txt' exsit prior to running the bulk insert? The file should not exist before running the insert.
My blog: http://jahaines.blogspot.com
|
|
|
|
|
SSC Veteran
      
Group: General Forum Members
Last Login: Wednesday, June 05, 2013 7:16 AM
Points: 258,
Visits: 353
|
|
| no it doesn't. it gets created and then deleted when the transaction is rolled back.
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: Yesterday @ 1:29 PM
Points: 2,278,
Visits: 3,011
|
|
How are you running the procedure from SSMS query window or command line and do you have the insert wrapped in a transaction with a try/catch or xact_abort?
My blog: http://jahaines.blogspot.com
|
|
|
|