473,756 Members | 5,955 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_send mail @recipients=@TO List,
@copy_recipient s=@CCList,@subj ect='the subject goes
here',@message= @MailText,@no_o utput=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 2486

"Rolf Kemper" <Ke*****@ee.nec .de> wrote in message
news:bb******** *************** ***@posting.goo gle.com...
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_send mail @recipients=@TO List,
@copy_recipient s=@CCList,@subj ect='the subject goes
here',@message= @MailText,@no_o utput=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_IDENTIFI ER ON
GO
SET ANSI_NULLS ON
GO

CREATE TRIGGER tr1_ProjectTask s_tab
ON dbo.ProjectTask s_tab
FOR UPDATE
AS
IF ( UPDATE(IsFinish ed) )
BEGIN
SET NOCOUNT ON
DECLARE @ProjectTasks_I D int
DECLARE @Employees_ID int
DECLARE @AllocationDela y 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_I D=ProjectTasks_ ID,
@Employees_ID=L astEditedBy,
@AllocationDela y=AllocationDel ay,
@AllocationTime =AllocationTime ,
@IsFinished=IsF inished
FROM ProjectTasks_ta b
WHERE ProjectTasks_ID IN ( SELECT ProjectTasks_ID FROM INSERTED )
--print '2_tr1_ProjectT asks_tab' -- UPDATE on IsFinished column

IF ( @IsFinished = 1 )
BEGIN
--print '3_tr1_ProjectT asks_tab' -- VALUE is 1
IF EXISTS ( SELECT * FROM
smdb.dbo.const_ ProjectStatusDe layTolerances_t ab
WHERE Duration = @AllocationTime AND @AllocationDela y >
MessageToleranc e )
BEGIN
SELECT @TOList=TOList , @CCList=CCList
FROM smdb.dbo.Create MailingList ('ToEmployeeCcH isBoss' ,
@Employees_ID ,default,defaul t,default )

SET @MailText='Text 1' + @CRLF
SET @MailText=@Mail Text + Text2' + @CRLF
+@CRLF
SET @MailText=@Mail Text +
'http://intra.etc.nec.d e/ProjectStatus/QuickStatus.asp ?TaskID=' +
CAST(@ProjectTa sks_ID as varchar(12)) + @CRLF + @CRLF
SET @MailText=@Mail Text + Text3'

EXEC @Status = master..xp_send mail @recipients=@TO List,
@copy_recipient s=@CCList,
@subject='Text3 ',
@message=@MailT ext,
@no_output=TRUE
END
END
END

GO
SET QUOTED_IDENTIFI ER OFF
GO
SET ANSI_NULLS ON
GO

############### ############### # end
############### ############### #########
"Greg D. Moore \(Strider\)" <mo************ ****@greenms.co m> wrote in message news:<7h******* ***********@twi ster.nyroc.rr.c om>...
"Rolf Kemper" <Ke*****@ee.nec .de> wrote in message
news:bb******** *************** ***@posting.goo gle.com...
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_send mail @recipients=@TO List,
@copy_recipient s=@CCList,@subj ect='the subject goes
here',@message= @MailText,@no_o utput=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_IDENTIFI ER ON
GO
SET ANSI_NULLS ON
GO

CREATE TRIGGER tr1_ProjectTask s_tab
ON dbo.ProjectTask s_tab
FOR UPDATE
AS
IF ( UPDATE(IsFinish ed) )
BEGIN
SET NOCOUNT ON
DECLARE @ProjectTasks_I D int
DECLARE @Employees_ID int
DECLARE @AllocationDela y 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_I D=ProjectTasks_ ID,
@Employees_ID=L astEditedBy,
@AllocationDela y=AllocationDel ay,
@AllocationTime =AllocationTime ,
@IsFinished=IsF inished
FROM ProjectTasks_ta b
WHERE ProjectTasks_ID IN ( SELECT ProjectTasks_ID FROM INSERTED )
--print '2_tr1_ProjectT asks_tab' -- UPDATE on IsFinished column

IF ( @IsFinished = 1 )
BEGIN
--print '3_tr1_ProjectT asks_tab' -- VALUE is 1
IF EXISTS ( SELECT * FROM
smdb.dbo.const_ ProjectStatusDe layTolerances_t ab
WHERE Duration = @AllocationTime AND @AllocationDela y >
MessageToleranc e )
BEGIN
SELECT @TOList=TOList , @CCList=CCList
FROM smdb.dbo.Create MailingList ('ToEmployeeCcH isBoss' ,
@Employees_ID ,default,defaul t,default )

SET @MailText='Text 1' + @CRLF
SET @MailText=@Mail Text + Text2' + @CRLF
+@CRLF
SET @MailText=@Mail Text +
'http://intra.etc.nec.d e/ProjectStatus/QuickStatus.asp ?TaskID=' +
CAST(@ProjectTa sks_ID as varchar(12)) + @CRLF + @CRLF
SET @MailText=@Mail Text + Text3'

EXEC @Status = master..xp_send mail @recipients=@TO List,
@copy_recipient s=@CCList,
@subject='Text3 ',
@message=@MailT ext,
@no_output=TRUE
END
END
END

GO
SET QUOTED_IDENTIFI ER OFF
GO
SET ANSI_NULLS ON
GO

############### ############### # end
############### ############### #########
"Greg D. Moore \(Strider\)" <mo************ ****@greenms.co m> wrote in message news:<7h******* ***********@twi ster.nyroc.rr.c om>...
"Rolf Kemper" <Ke*****@ee.nec .de> wrote in message
news:bb******** *************** ***@posting.goo gle.com...
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_send mail @recipients=@TO List,
@copy_recipient s=@CCList,@subj ect='the subject goes
here',@message= @MailText,@no_o utput=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****@sommarsk og.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.goo gle.com...
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_IDENTIFI ER ON
GO
SET ANSI_NULLS ON
GO

CREATE TRIGGER tr1_ProjectTask s_tab
ON dbo.ProjectTask s_tab
FOR UPDATE
AS
IF ( UPDATE(IsFinish ed) )
BEGIN
SET NOCOUNT ON
DECLARE @ProjectTasks_I D int
DECLARE @Employees_ID int
DECLARE @AllocationDela y 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_I D=ProjectTasks_ ID,
@Employees_ID=L astEditedBy,
@AllocationDela y=AllocationDel ay,
@AllocationTime =AllocationTime ,
@IsFinished=IsF inished
FROM ProjectTasks_ta b
WHERE ProjectTasks_ID IN ( SELECT ProjectTasks_ID FROM INSERTED )
--print '2_tr1_ProjectT asks_tab' -- UPDATE on IsFinished column

IF ( @IsFinished = 1 )
BEGIN
--print '3_tr1_ProjectT asks_tab' -- VALUE is 1
IF EXISTS ( SELECT * FROM
smdb.dbo.const_ ProjectStatusDe layTolerances_t ab
WHERE Duration = @AllocationTime AND @AllocationDela y >
MessageToleranc e )
BEGIN
SELECT @TOList=TOList , @CCList=CCList
FROM smdb.dbo.Create MailingList ('ToEmployeeCcH isBoss' ,
@Employees_ID ,default,defaul t,default )

SET @MailText='Text 1' + @CRLF
SET @MailText=@Mail Text + Text2' + @CRLF
+@CRLF
SET @MailText=@Mail Text +
'http://intra.etc.nec.d e/ProjectStatus/QuickStatus.asp ?TaskID=' +
CAST(@ProjectTa sks_ID as varchar(12)) + @CRLF + @CRLF
SET @MailText=@Mail Text + Text3'

EXEC @Status = master..xp_send mail @recipients=@TO List,
@copy_recipient s=@CCList,
@subject='Text3 ',
@message=@MailT ext,
@no_output=TRUE
END
END
END

GO
SET QUOTED_IDENTIFI ER OFF
GO
SET ANSI_NULLS ON
GO

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

message news:<7h******* ***********@twi ster.nyroc.rr.c om>...
"Rolf Kemper" <Ke*****@ee.nec .de> wrote in message
news:bb******** *************** ***@posting.goo gle.com...
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_send mail @recipients=@TO List,
@copy_recipient s=@CCList,@subj ect='the subject goes
here',@message= @MailText,@no_o utput=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
1297
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 getting the parameters passed to the procedure correctly, or just in using stored procedures from ASP. I can execute this SQL from Query Analyzer fine: xp_sendmail "testuser", "Hello World!"
2
23651
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
6948
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'. The stored procedure will still be created. does this mean that only dependencies involving xp_sendmail will not be stored? the other dependencies appear to be fine. i'm not sure why sql would even bother telling me this info. thoughts?
6
2472
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 output on a separate line. I have no idea why this is happenening, I've never seen it before. The code looks like this; EXEC master.dbo.xp_sendmail @recipients = '<email address>', @dbuse = 'TestDB',
1
1664
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 statement to send mail to a Yahoo account and it was received. Is there a way to be able to send email using SQL xp_sendmail to a Hotmail account?
1
3007
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 an xp_sendmail example of how to do this. The results of a query can easily appear in the body of the email but all my attempts to include the contents of a file in the body of the email have not worked. TIA
1
1372
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 account of the mapi on my server. Can someone give a hint to solve this problem ? thanks
2
3150
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 tried the following: 1)Checking SQL and SQLAgents accounts all match up with default mail profile.
1
3888
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 Windows authentication and have given myself full admin rights in MSSQL. Which account is mssql trying to send the email from? Is it the servers or my local clients?
0
10040
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9873
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9846
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9713
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8713
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7248
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6534
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3806
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2666
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.