Hi. So far i can capture the overall error of a bulk insert.Truncate table [dbo].[dbfile];Begin Trybegin BULK INSERT [dbo].[dbfile]FROM 'C:\works\databasebulks\test.txt'WITH (MAXERRORS = 500000,LASTROW = 100, --CODEPAGE ='ACP', --CODEPAGE = '65001',--CODEPAGE ='1252',--CODEPAGE ='RAW',FORMATFILE='C:\work\databasebulks\dbxmlformatfiletests.xml'); endEnd TryBegin CATCHbeginINSERT INTO [dbo].DBInsertErrors(ErrorNumber, ErrorSeverity, ErrorState, ErrorProcedure, ErrorLine, ErrorMessage, DateTimeStamp)SELECTERROR_NUMBER() AS ErrorNumber,ERROR_SEVERITY() AS ErrorSeverity,ERROR_STATE() as ErrorState,ERROR_PROCEDURE() as ErrorProcedure,ERROR_LINE() as ErrorLine,'CSV File Bulk_Insert: ' + ERROR_MESSAGE() as ErrorMessage,GetDate() as DateTimeStamp;Print('** Bulk Insert Process error: see table dbo.ProcessCSV_Error for details.**')endend catch
This will give an overall error on only one row.I was wondering if it is possible to capture the row errors. What i mean is that if only run this portion:BULK INSERT [dbo].[dbfile]FROM 'C:\works\databasebulks\test.txt'WITH (MAXERRORS = 500000,LASTROW = 100, FORMATFILE='C:\work\databasebulks\dbxmlformatfiletests.xml');
It will start, for example, complaining that line 3 is not well formatted, line 8 codepage is wrong,etc. HOWEVER, it will continue the validation and insert lines since the MAXERRORS i set, let it slide. I would like though to be able to record these exceptions, even though they will not affect the final bulk insert.Thanks.