Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 RAISERROR not raising error!

Author  Topic 

Anna
Starting Member

20 Posts

Posted - 2001-03-23 : 11:02:57
I have a stored procedure which checks whether a company name already exists in the table before inserting. If the company name is already there, it doesn't try and insert, just raises an error.
This error should be passed back to some ASP script and be handled there, however when we run it, the insert doesn't take place, but no error message is dealt with.

My SQL is:

select @customer_exists = count(*) from C01_CUSTOMER where c01_company_name = @company_name
if @customer_exists = 0
begin

insert into C01_CUSTOMER(c01_company_name) values(@company_name)
select @hold_new_id = @@identity

--just check we've got the new id number
if @hold_new_id is null
begin
RAISERROR('ERROR: Allocation of customer id failed',1,1)
end
--book the new customer out to whoever's just created it
insert into T17_OFFLINE_CUSTOMERS values(@hold_new_id,@user_id,@download_directory)

end

else

RAISERROR('ERROR: Customer with this company name already exists, customer not created',1,1)

GO



The ASP checks by doing if Err.number <> 0 then.

We're not sure if the error message is being passed from SQLServer. When I run the proc in SQL Query analyser I get the error message fine.

Any insights would be appreciated.


Anna
   

- Advertisement -