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???
Microsoft SQL Server

Avatar of undefined
Last Comment
Aneesh

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Aneesh

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Aneesh

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
Aneesh

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
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes