473,398 Members | 2,404 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

error handling and bulk insert

I do not understand the error handling of SQL Server here. Any error in
bulk insert seems to halt the current T-SQL statement entirely, rendering
it impossible to log an error. The first statement below executes as
expected, and were I to replace "print" with something meaningful I could
do some useful error handling. The second statement just seems to totally
bail out after the error, preventing me from doing any useful error
handling. This is a problem b/c I would like to schedule bulk inserts and
need to be notified if there is a problem.

The following can be run in QA to demonstrate:

print 'BEFORE TYPICAL ERROR'
raiserror('Some Error', 16, 10)
if (@@ERROR <> 0) print 'I can catch and log this error - good!' else
print 'I can not catch and log this error - bad!'
print 'AFTER TYPICAL ERROR'
go

print 'BEFORE BULK INSERT'
Bulk insert Northwind.dbo.orders
from 'ThisFileDoesNotExist'
if (@@ERROR <> 0) print 'I can catch and log this error - good!' else
print 'I can not catch and log this error - bad!'
print 'AFTER BULK INSERT'
go
TIA,
Dave

Dec 2 '05 #1
1 9896
Metal Dave (me***@spam.spam) writes:
I do not understand the error handling of SQL Server here. Any error in
bulk insert seems to halt the current T-SQL statement entirely, rendering
it impossible to log an error. The first statement below executes as
expected, and were I to replace "print" with something meaningful I could
do some useful error handling. The second statement just seems to totally
bail out after the error, preventing me from doing any useful error
handling. This is a problem b/c I would like to schedule bulk inserts and
need to be notified if there is a problem.


That's the way error handling in SQL 2000 works. Some errors terminates
the current statment only. Others aborts the batch and rolls back the
current transaction. Compilation error terminates the current scope.
The net effect is that you cannot trap all errors in T-SQL.

For a longer discussion on the topic, I have two articles on on my
web site: http://www.sommarskog.se/error-handling-I.html and
http://www.sommarskog.se/error-handling-II.html

In SQL 2005 the situation is entirely different as you can set up an
error handler with TRY CATCH.

--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Dec 2 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Niraj Khandwala | last post by:
Dear all, this error handling has been a pain since so manya days using ASP 3.0 with IIS 5.0 on W2K server Created a custom error page using the Server.GetLastError() and works fine in most of...
3
by: Loi | last post by:
Hi All, I use Bulk insert to put data to myTable. When the SQL server is in local machin, it works well. But when I put the data in a sql server situated not locally, then I get a error message...
4
by: Mike | last post by:
I am getting a type mismatch error when I do a bulk insert. ---Begin Error Msg--- Server: Msg 4864, Level 16, State 1, Line 1 Bulk insert data conversion error (type mismatch) for row 1, column...
9
by: Ron | last post by:
my application is throwing an exception error when closing if I run a procedure in the app. I can't even trap the error with try/catch ex As Exception. Is there a way to completely shut down the...
0
by: Peter Nofelt | last post by:
Hi all, ISSUE: ==================== In SQL 2005 (sp2) I get the following error when preforming a bulk insert with an associated xml format file: "Could not bulk insert. Unknown version of...
2
by: AB | last post by:
Hi to all, I have a problem about a importation of a file *.csv with SQL Server, through a bulk insert, called in a store procedure that a c# sw calls. This is the description of the error:...
2
by: nano | last post by:
Does sql server have a way to handle errors in a sproc which would allow one to insert rows, ignoring rows which would create a duplicate key violation? I know if one loops one can handle the error...
7
by: girl | last post by:
Hi i have a problem with MS SQL server 2000 and hope to seek for some advise. i have the following samples aa|0|abcdefg| b|0|abcdefg| i used the bulk insert in the query analyser.. BULK...
1
by: craigmold | last post by:
Hi Guys, I'm new to this forum, so please be gentle! I'm running bulk insert dynamically using sp_executesql. I've setup error handling in the dynamic code. It works when all is well, however...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.