February 13, 2006 at 2:38 am
When I try to execute SP, which contains Bulk insert command, the contents of the file are processed correctly. Later there is a graceful exit from the SP.
However when the file can not be found, then the bulk insert terminates the SP/Batch and the error is not trapped. (I mean error number is not available in @@Error).
Is there any way we can trap this error?
February 13, 2006 at 10:06 pm
February 14, 2006 at 11:24 am
you can use a xp_fileexists function to check whether the file exists or not(EXEC master..xp_fileexist 'c:\boot.ini') , it will return 3 columns , if file exists file exists column returns 1 and 0 if file not exists,
example code:
create table #fileinfo(
FileExists bit , IsDirectory bit ,ParentDirectoryExists bit)
Insert #fileinfo(FileExists,IsDirectory,ParentDirectoryExists)
EXEC master..xp_fileexist 'c:\boot.ini'
IF (select FileExists from #fileinfo) = 1
begin
BULKINSERT .....logic here
end
else
begin
raiserror ()....logic here...
end
bondada
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply