Link to home
Start Free TrialLog in
Avatar of tullulahbell
tullulahbell

asked on

Raise error in SQL - stored procedure

Hi

I have a stored procedure which sends an email.  This procedure is called from access, I need to write a stored procedure which will raise an error in access should the initial stored procedure fails.  Any ideas??

I've been told I need to handle for error nos 4 and 16???
ASKER CERTIFIED SOLUTION
Avatar of Aneesh
Aneesh
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
got this from one of the sites



create proc dbo.sendmail
@recipients             varchar(8000) = NULL,
@message                 varchar(8000) = NULL,
@query                     varchar(8000) = NULL,    -- parameter will not be used
@attachments             varchar(8000) = NULL,
@copy_recipients        varchar(8000) = NULL,
@blind_copy_recipients    varchar(8000) = NULL,
@subject                 varchar(8000) = 'SQL Server Message',
@type                     varchar(8000) = NULL,
@attach_results         varchar(8000) = NULL,    -- parameter will not be used
@no_output                 varchar(8000) = 'FALSE',-- parameter will not be used
@no_header                 varchar(8000) = 'FALSE',-- parameter will not be used
@width                     int = 80,                -- parameter will not be used
@separator                 varchar(8000) = NULL,    -- parameter will not be used
@echo_error             varchar(8000) = NULL,    -- parameter will not be used
@set_user                 varchar(8000) = NULL,    -- parameter will not be used
@dbuse                     varchar(8000) = NULL    -- parameter will not be used

as

declare @rc int

exec @rc = master.dbo.xp_smtp_sendmail
    @FROM         = N'xp_sendmail@domain.com',    -- change value to suite your own needs
    @FROM_NAME   = N'xp_sendmail procedure',    -- change value to suite your own needs
    @TO             = @recipients,
    @replyto     = @recipients,                    -- change value to suite your own needs
    @CC             = @copy_recipients,
    @BCC         = @blind_copy_recipients,
    @priority    = N'normal',                    -- change value to suite your own needs
    @subject     = @subject,
    @message     = @message,
--    @messagefile = @messagefile,                -- no equivalent parameter value available
    @type         = N'text/plain',                -- change value to suite your own needs
--    @attachment  = @attachment,                    -- no equivalent parameter value available
    @attachments = @attachments,
    @server         = N'smarthost',                -- change value to suite your own needs, like mail.domain.com
--    @codepage    = @codepage,
    @timeout     = 10000                         -- change value to suite your own needs

if (@@error <> 0 or @rc <> 0)
    raiserror(N'Sending message using xp_sendmail failed', 16, 1)

return @rc
go
Thanks for grade 'B', Hope i didn't miss anything.

As a member i request you to gothru the user terms and have a look at these section

https://www.experts-exchange.com/help.jsp#hi73
https://www.experts-exchange.com/help.jsp#hi18