Catching an uncaptured error in SQL

Tags:
CSV
SQL
SQL Server errors
This is a batch of SQL code I’ve been using: BEGIN TRY begin BULK INSERT DBXMRPAS2.dbo.[STG_drive] FROM 'Wdmyitpxmdev1xmmsbcpcsvfile20080715drive.200807151100.extracting' WITH ( MAXERRORS =1000, FIELDTERMINATOR = '^', ROWTERMINATOR = '|n' ) end END TRY BEGIN CATCH SELECT 'Error Caught' SELECT ERROR_MESSAGE(), ERROR_NUMBER() END CATCH Why would an error from this statement not be captured by the catch if the .CSV file is missing for the given directory?
ASKED: July 15, 2008  6:52 PM
UPDATED: July 16, 2008  12:10 AM

Answer Wiki

Thanks. We'll let you know when a new response is added.

I’m not sure why it isn’t catching the error. I would assume because BULK INSERT is throwing an OS error not a SQL error.

I would recommend checking to see if the file exists prior to attempting the BULK INSERT command. You can do this via the xp_fileexist. You can see an example of use <a href=”http://searchsqlserver.techtarget.com/tip/0,289483,sid87_gci1270919,00.html”>here</a>.

Discuss This Question: 1  Reply

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following