473,387 Members | 1,486 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

xp_sendmail blocks trigger ?

Dear All,

we are running SQL2000 Sever and make use of the xp_sendmail.

For any reason the mail service can run into problems and it looks
like that the statemnt below gets not finished.

EXEC @Status = master..xp_sendmail @recipients=@TOList,
@copy_recipients=@CCList,@subject='the subject goes
here',@message=@MailText,@no_output=TRUE

Unfortunately the statement is in an update trigger and hence it
blocks the table for any further updates.

My questions are:
Can I achieve a kind of timeout check in my trigger in order to bypass
the
xp_sendmail call ?

In general, sending mail in a trigger may not be a good idea.
How can this be solved better ?
Any hint is highly welcome
Regards
Rolf
Jul 20 '05 #1
6 2463

"Rolf Kemper" <Ke*****@ee.nec.de> wrote in message
news:bb**************************@posting.google.c om...
Dear All,

we are running SQL2000 Sever and make use of the xp_sendmail.

For any reason the mail service can run into problems and it looks
like that the statemnt below gets not finished.

EXEC @Status = master..xp_sendmail @recipients=@TOList,
@copy_recipients=@CCList,@subject='the subject goes
here',@message=@MailText,@no_output=TRUE

Unfortunately the statement is in an update trigger and hence it
blocks the table for any further updates.

My questions are:
Can I achieve a kind of timeout check in my trigger in order to bypass
the
xp_sendmail call ?

In general, sending mail in a trigger may not be a good idea.
May is an understatement.

Triggers need to execute as quickly as possible.

Anything calling an external DLL is going to be an issue in more ways than
one as you've discovered.

How can this be solved better ?
What exactly are you trying to do? (i.e. why send the email in the trigger?)



Any hint is highly welcome
Regards
Rolf

Jul 20 '05 #2
you can take the status of the update/insert trigger and put a IF
condition to send a email notification.

Thank you
Raju
Jul 20 '05 #3
Dear Greg,

thank you for offering some help. You confirmed my fear that my
approch is bad in general. So, if you can offer a strategie please let
me know. In particular,
where can I get more about the things to consider when using external
DLL.

Here is the code. I just cut the version comments in header and text
in the mail to make it shorter.

Thanks a lot
Rolf
#################### code of trigger #############################
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

CREATE TRIGGER tr1_ProjectTasks_tab
ON dbo.ProjectTasks_tab
FOR UPDATE
AS
IF ( UPDATE(IsFinished) )
BEGIN
SET NOCOUNT ON
DECLARE @ProjectTasks_ID int
DECLARE @Employees_ID int
DECLARE @AllocationDelay int
DECLARE @AllocationTime int
DECLARE @LastEditedBy int
DECLARE @IsFinished bit
DECLARE @TOList nvarchar(1000)
DECLARE @CCList nvarchar(2000)
DECLARE @MailText nvarchar(1000)
DECLARE @Status int
DECLARE @CRLF char(2)

SET @CRLF = CHAR(10) + CHAR(13)

SELECT @ProjectTasks_ID=ProjectTasks_ID,
@Employees_ID=LastEditedBy,
@AllocationDelay=AllocationDelay,
@AllocationTime=AllocationTime,
@IsFinished=IsFinished
FROM ProjectTasks_tab
WHERE ProjectTasks_ID IN ( SELECT ProjectTasks_ID FROM INSERTED )
--print '2_tr1_ProjectTasks_tab' -- UPDATE on IsFinished column

IF ( @IsFinished = 1 )
BEGIN
--print '3_tr1_ProjectTasks_tab' -- VALUE is 1
IF EXISTS ( SELECT * FROM
smdb.dbo.const_ProjectStatusDelayTolerances_tab
WHERE Duration = @AllocationTime AND @AllocationDelay >
MessageTolerance )
BEGIN
SELECT @TOList=TOList , @CCList=CCList
FROM smdb.dbo.CreateMailingList ('ToEmployeeCcHisBoss' ,
@Employees_ID ,default,default,default )

SET @MailText='Text1' + @CRLF
SET @MailText=@MailText + Text2' + @CRLF
+@CRLF
SET @MailText=@MailText +
'http://intra.etc.nec.de/ProjectStatus/QuickStatus.asp?TaskID=' +
CAST(@ProjectTasks_ID as varchar(12)) + @CRLF + @CRLF
SET @MailText=@MailText + Text3'

EXEC @Status = master..xp_sendmail @recipients=@TOList,
@copy_recipients=@CCList,
@subject='Text3',
@message=@MailText,
@no_output=TRUE
END
END
END

GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

############################### end
#######################################
"Greg D. Moore \(Strider\)" <mo****************@greenms.com> wrote in message news:<7h******************@twister.nyroc.rr.com>.. .
"Rolf Kemper" <Ke*****@ee.nec.de> wrote in message
news:bb**************************@posting.google.c om...
Dear All,

we are running SQL2000 Sever and make use of the xp_sendmail.

For any reason the mail service can run into problems and it looks
like that the statemnt below gets not finished.

EXEC @Status = master..xp_sendmail @recipients=@TOList,
@copy_recipients=@CCList,@subject='the subject goes
here',@message=@MailText,@no_output=TRUE

Unfortunately the statement is in an update trigger and hence it
blocks the table for any further updates.

My questions are:
Can I achieve a kind of timeout check in my trigger in order to bypass
the
xp_sendmail call ?

In general, sending mail in a trigger may not be a good idea.


May is an understatement.

Triggers need to execute as quickly as possible.

Anything calling an external DLL is going to be an issue in more ways than
one as you've discovered.

How can this be solved better ?


What exactly are you trying to do? (i.e. why send the email in the trigger?)



Any hint is highly welcome
Regards
Rolf

Jul 20 '05 #4
Dear Greg,

thank you for offering some help. You confirmed my fear that my
approch is bad in general. So, if you can offer a strategie please let
me know. In particular,
where can I get more about the things to consider when using external
DLL.

Here is the code. I just cut the version comments in header and text
in the mail to make it shorter.

Thanks a lot
Rolf
#################### code of trigger #############################
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

CREATE TRIGGER tr1_ProjectTasks_tab
ON dbo.ProjectTasks_tab
FOR UPDATE
AS
IF ( UPDATE(IsFinished) )
BEGIN
SET NOCOUNT ON
DECLARE @ProjectTasks_ID int
DECLARE @Employees_ID int
DECLARE @AllocationDelay int
DECLARE @AllocationTime int
DECLARE @LastEditedBy int
DECLARE @IsFinished bit
DECLARE @TOList nvarchar(1000)
DECLARE @CCList nvarchar(2000)
DECLARE @MailText nvarchar(1000)
DECLARE @Status int
DECLARE @CRLF char(2)

SET @CRLF = CHAR(10) + CHAR(13)

SELECT @ProjectTasks_ID=ProjectTasks_ID,
@Employees_ID=LastEditedBy,
@AllocationDelay=AllocationDelay,
@AllocationTime=AllocationTime,
@IsFinished=IsFinished
FROM ProjectTasks_tab
WHERE ProjectTasks_ID IN ( SELECT ProjectTasks_ID FROM INSERTED )
--print '2_tr1_ProjectTasks_tab' -- UPDATE on IsFinished column

IF ( @IsFinished = 1 )
BEGIN
--print '3_tr1_ProjectTasks_tab' -- VALUE is 1
IF EXISTS ( SELECT * FROM
smdb.dbo.const_ProjectStatusDelayTolerances_tab
WHERE Duration = @AllocationTime AND @AllocationDelay >
MessageTolerance )
BEGIN
SELECT @TOList=TOList , @CCList=CCList
FROM smdb.dbo.CreateMailingList ('ToEmployeeCcHisBoss' ,
@Employees_ID ,default,default,default )

SET @MailText='Text1' + @CRLF
SET @MailText=@MailText + Text2' + @CRLF
+@CRLF
SET @MailText=@MailText +
'http://intra.etc.nec.de/ProjectStatus/QuickStatus.asp?TaskID=' +
CAST(@ProjectTasks_ID as varchar(12)) + @CRLF + @CRLF
SET @MailText=@MailText + Text3'

EXEC @Status = master..xp_sendmail @recipients=@TOList,
@copy_recipients=@CCList,
@subject='Text3',
@message=@MailText,
@no_output=TRUE
END
END
END

GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

############################### end
#######################################
"Greg D. Moore \(Strider\)" <mo****************@greenms.com> wrote in message news:<7h******************@twister.nyroc.rr.com>.. .
"Rolf Kemper" <Ke*****@ee.nec.de> wrote in message
news:bb**************************@posting.google.c om...
Dear All,

we are running SQL2000 Sever and make use of the xp_sendmail.

For any reason the mail service can run into problems and it looks
like that the statemnt below gets not finished.

EXEC @Status = master..xp_sendmail @recipients=@TOList,
@copy_recipients=@CCList,@subject='the subject goes
here',@message=@MailText,@no_output=TRUE

Unfortunately the statement is in an update trigger and hence it
blocks the table for any further updates.

My questions are:
Can I achieve a kind of timeout check in my trigger in order to bypass
the
xp_sendmail call ?

In general, sending mail in a trigger may not be a good idea.


May is an understatement.

Triggers need to execute as quickly as possible.

Anything calling an external DLL is going to be an issue in more ways than
one as you've discovered.

How can this be solved better ?


What exactly are you trying to do? (i.e. why send the email in the trigger?)



Any hint is highly welcome
Regards
Rolf

Jul 20 '05 #5
Rolf Kemper (Ke*****@ee.nec.de) writes:
thank you for offering some help. You confirmed my fear that my
approch is bad in general. So, if you can offer a strategie please let
me know. In particular,
where can I get more about the things to consider when using external
DLL.

Here is the code. I just cut the version comments in header and text
in the mail to make it shorter.


One way is to write the mailing task to a table, and then have an SQL
Agent job to poll that table and send the mail.

--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 20 '05 #6

"Rolf Kemper" <Ke*****@ee.nec.de> wrote in message
news:bb**************************@posting.google.c om...
Dear Greg,

thank you for offering some help. You confirmed my fear that my
approch is bad in general. So, if you can offer a strategie please let
me know. In particular,
where can I get more about the things to consider when using external
DLL.
Again, need to know what exactly your ultimate goal is.

As Erland I think it was said, perhaps having a scheduled task firing off
every minute or so is the best way to go.


Here is the code. I just cut the version comments in header and text
in the mail to make it shorter.

Thanks a lot
Rolf
#################### code of trigger #############################
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

CREATE TRIGGER tr1_ProjectTasks_tab
ON dbo.ProjectTasks_tab
FOR UPDATE
AS
IF ( UPDATE(IsFinished) )
BEGIN
SET NOCOUNT ON
DECLARE @ProjectTasks_ID int
DECLARE @Employees_ID int
DECLARE @AllocationDelay int
DECLARE @AllocationTime int
DECLARE @LastEditedBy int
DECLARE @IsFinished bit
DECLARE @TOList nvarchar(1000)
DECLARE @CCList nvarchar(2000)
DECLARE @MailText nvarchar(1000)
DECLARE @Status int
DECLARE @CRLF char(2)

SET @CRLF = CHAR(10) + CHAR(13)

SELECT @ProjectTasks_ID=ProjectTasks_ID,
@Employees_ID=LastEditedBy,
@AllocationDelay=AllocationDelay,
@AllocationTime=AllocationTime,
@IsFinished=IsFinished
FROM ProjectTasks_tab
WHERE ProjectTasks_ID IN ( SELECT ProjectTasks_ID FROM INSERTED )
--print '2_tr1_ProjectTasks_tab' -- UPDATE on IsFinished column

IF ( @IsFinished = 1 )
BEGIN
--print '3_tr1_ProjectTasks_tab' -- VALUE is 1
IF EXISTS ( SELECT * FROM
smdb.dbo.const_ProjectStatusDelayTolerances_tab
WHERE Duration = @AllocationTime AND @AllocationDelay >
MessageTolerance )
BEGIN
SELECT @TOList=TOList , @CCList=CCList
FROM smdb.dbo.CreateMailingList ('ToEmployeeCcHisBoss' ,
@Employees_ID ,default,default,default )

SET @MailText='Text1' + @CRLF
SET @MailText=@MailText + Text2' + @CRLF
+@CRLF
SET @MailText=@MailText +
'http://intra.etc.nec.de/ProjectStatus/QuickStatus.asp?TaskID=' +
CAST(@ProjectTasks_ID as varchar(12)) + @CRLF + @CRLF
SET @MailText=@MailText + Text3'

EXEC @Status = master..xp_sendmail @recipients=@TOList,
@copy_recipients=@CCList,
@subject='Text3',
@message=@MailText,
@no_output=TRUE
END
END
END

GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

############################### end
#######################################
"Greg D. Moore \(Strider\)" <mo****************@greenms.com> wrote in

message news:<7h******************@twister.nyroc.rr.com>.. .
"Rolf Kemper" <Ke*****@ee.nec.de> wrote in message
news:bb**************************@posting.google.c om...
Dear All,

we are running SQL2000 Sever and make use of the xp_sendmail.

For any reason the mail service can run into problems and it looks
like that the statemnt below gets not finished.

EXEC @Status = master..xp_sendmail @recipients=@TOList,
@copy_recipients=@CCList,@subject='the subject goes
here',@message=@MailText,@no_output=TRUE

Unfortunately the statement is in an update trigger and hence it
blocks the table for any further updates.

My questions are:
Can I achieve a kind of timeout check in my trigger in order to bypass
the
xp_sendmail call ?

In general, sending mail in a trigger may not be a good idea.


May is an understatement.

Triggers need to execute as quickly as possible.

Anything calling an external DLL is going to be an issue in more ways than one as you've discovered.

How can this be solved better ?


What exactly are you trying to do? (i.e. why send the email in the trigger?)


Any hint is highly welcome
Regards
Rolf

Jul 20 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Jeff Cochran | last post by:
Does anyone have a code snippet or example on using the xp_sendmail SQL procedure from an ASP page (VBscript)? I have no problem with the stored procedure from a query and I think my problem is...
2
by: Jürgen Hetzel | last post by:
Hello! My environment is: Win 2000 Server, MS SQL-Server 2000 (SP2) and MS ExchangeServer 5.5 the two following TransactSQL-codepieces show different results: 1. with attachment
1
by: Ted Theodoropoulos | last post by:
when creating a sp in SQL 2K that uses xp_sendmail i get a message saying: Cannot add rows to sysdepends for the current stored procedure because it depends on the missing object 'xp_sendmail'....
6
by: Nathan Griffiths | last post by:
I have been testing our SQL Mail setup in SQL Server 2000 (sp3a) and have found that when I attach results as a file, every other character is a control character which causes each real character...
1
by: mike | last post by:
Using the Query Analyzer, I issued the statement "EXEC xp_sendmail 'anyone@hotmail.com, 'Test.'" and received 'email sent' confirmation. But, my email was never received. I used the same...
1
by: Michael McGarrigle | last post by:
I would like to send the contents of a file using xp_sendmail however I do not want the file contents to be an attachment. I have no problem sending the file as an attachement. Can anybody give me...
1
by: telenet | last post by:
I'm working with sqlserver2000 on a server2003. My e-mail via xp_sendmail is working good. But I have one problem --> every mail I send via xp_sendmail does not appear in de sent-items van the...
2
by: Eric Timely | last post by:
After a trust with exchange server established the xp_SendMail gives the following error: xp_sendmail: failed with mail error 0x80070005 Prior to the trust everything worked fine. I have...
1
by: Stephen2 | last post by:
I'm trying to send an email using master..xp_sendmail with parms and the default Outlook profile. I can successfully test the profile on my own computer and on the server. I'm running using...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.