all groups > sql server (alternate) > august 2004 >
You're in the

sql server (alternate)

group:

Error catch in SQL


Re: Error catch in SQL Erland Sommarskog
8/29/2004 9:48:04 PM
sql server (alternate):
Mark (markjones@n0Sp8mTAIRAWHITIdotAC.NZ) writes:
[quoted text, click to view]

In T-SQL there is no way to suppress the error. (In SQL2000, that is. The
coming version SQL2005 has the TRY CATCH you are looking for.

Presumably you should be able to have the DTS package to swallow the
error, but I don't know DTS so I can't give any details. The nice and
friendly people in microsoft.public.sqlserver.dts may have some ideas.


--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Books Online for SQL Server SP3 at
Error catch in SQL Mark
8/30/2004 8:20:59 AM
Hi everyone, I am using an SQL extended stored procedure to send emails in a
DTS package using a cursor that goes through each row in a table.

Email sending code below
======================
exec master.dbo.xp_smtp_sendmail
@FROM = @sFrom,
@FROM_NAME = @sFrom,
@TO = @sRecepients,
@subject = @sSubject,
@message = @sBody,
@type = N'text/html',
@codepage = 0,
@server =N'MYMAILSERVER'
======================
Fetch Next From EmailCursor ...

Now the problem I have is that if an individual email address in invalid
then an error occurs and the whole DTS package falls over. What I would like
to be able to do is "catch the error", something like this (C# code used as
example)

try
{
exec master.dbo.xp_smtp_sendmail
@FROM = @sFrom,
@FROM_NAME = @sFrom,
@TO = @sRecepients,
@subject = @sSubject,
@message = @sBody,
@type = N'text/html',
@codepage = 0,
@server =N'MYMAILSERVER'
} catch {
exec master.dbo.xp_smtp_sendmail
@FROM = "arealaddress@mybusiness.com",
@FROM_NAME = @sFrom,
@TO = @sRecepients,
@subject = @sSubject,
@message = @sBody,
@type = N'text/html',
@codepage = 0,
@server =N'MYMAILSERVER'
}

Is this possible??? Normally I would do all the email validation before the
email is entered into the database but unfortunately, I do not have access
to the application code so I am stuck doing it this way.

Thanks in advance
Mark

Re: Error catch in SQL Mark
8/30/2004 12:07:40 PM
Thanks Erland
Regards
Mark
[quoted text, click to view]

AddThis Social Bookmark Button