Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase 12»»

Bulk insert t-sql command Expand / Collapse
Author
Message
Posted Friday, January 25, 2008 9:15 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: 2 days ago @ 7:52 AM
Points: 258, Visits: 401
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?
Post #447601
Posted Friday, January 25, 2008 12:57 PM
Mr or Mrs. 500

Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr 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?
Post #447773
Posted Friday, January 25, 2008 1:48 PM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: 2 days ago @ 7:52 AM
Points: 258, Visits: 401
bulk insert from "e:\datafile.bcp"
WITH (FORMATFILE = 'e:\formatfile.xml', maxerrors=0, errorfile='E:\import_error.txt')
Post #447803
Posted Friday, January 25, 2008 3:03 PM
Mr or Mrs. 500

Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr 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

Post #447840
Posted Friday, January 25, 2008 6:37 PM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: 2 days ago @ 7:52 AM
Points: 258, Visits: 401
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.
Post #447892
Posted Monday, January 28, 2008 8:11 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Saturday, July 12, 2014 6:43 PM
Points: 2,278, Visits: 3,051
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
Post #448342
Posted Monday, January 28, 2008 8:28 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: 2 days ago @ 7:52 AM
Points: 258, Visits: 401
I did, but it still deletes the file.
Post #448354
Posted Monday, January 28, 2008 8:36 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Saturday, July 12, 2014 6:43 PM
Points: 2,278, Visits: 3,051
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
Post #448367
Posted Monday, January 28, 2008 8:44 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: 2 days ago @ 7:52 AM
Points: 258, Visits: 401
no it doesn't. it gets created and then deleted when the transaction is rolled back.
Post #448376
Posted Monday, January 28, 2008 8:58 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Saturday, July 12, 2014 6:43 PM
Points: 2,278, Visits: 3,051
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
Post #448383
« Prev Topic | Next Topic »

Add to briefcase 12»»

Permissions Expand / Collapse