Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8337595
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T04:20:45+00:00 2026-06-09T04:20:45+00:00

Help! The following trigger results in blocking once executed: USE [Automation] GO /****** Object:

  • 0

Help! The following trigger results in blocking once executed:

USE [Automation]
GO
/****** Object:  Trigger [dbo].[AfterInsertSendEmail]    Script Date: 08/06/2012 22:05:54 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:      Chris Cannon
-- Create date: 20120806
-- Description: TBC
-- =============================================
ALTER TRIGGER [dbo].[AfterInsertSendEmail] 
   ON  [dbo].[Enquiry] 
   AFTER INSERT
AS 
BEGIN;
    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.
    SET NOCOUNT ON;

    -- Insert statements for trigger here
    DECLARE @l_profile_name nvarchar(128) = 'Automation Enquiries';
    DECLARE @l_importance varchar(6) = 'High';
    DECLARE @l_sensitivity varchar(12) = 'Personal';
    DECLARE @l_recipients varchar(500) = 'a.n.other@somewhere.co.uk';
    DECLARE @l_copy_recipients varchar(500) = 'b.n.other@somewhere.co.uk';
    DECLARE @l_blind_copy_recipients varchar(500) = 'c.n.other@somewhere.co.uk';
    DECLARE @l_reply_to varchar(500) = (SELECT [EmailAddress] FROM [inserted]);
    DECLARE @l_subject nvarchar(255) = (SELECT 'New Enquiry From ' + [FirstName] + ' ' + [LastName] FROM [inserted]);
    DECLARE @l_body nvarchar(500) = 'TBC';
    DECLARE @l_query nvarchar(500) = 'SELECT TOP(1) * FROM [Automation].[dbo].[Enquiry] ORDER BY [Id] DESC';
    DECLARE @l_query_result_separator char(1) = CHAR(9);
    DECLARE @l_query_result_no_padding bit = 1;
    DECLARE @l_attach_query_result_as_file bit = 1;
    DECLARE @l_query_attachment_filename nvarchar(260) = (SELECT 'automation_enquiry_' + REPLACE(REPLACE(REPLACE(CONVERT(nvarchar(19), [DateSubmitted], 120), '-', ''), ' ', ''), ':', '') + '.csv' FROM [inserted]);
    DECLARE @l_append_query_error bit = 1;

    EXEC [msdb].[dbo].[sp_send_dbmail]
          @profile_name = @l_profile_name
        , @importance = @l_importance
        , @sensitivity = @l_sensitivity
        , @recipients = @l_recipients
        , @copy_recipients = @l_copy_recipients
        , @blind_copy_recipients = @l_blind_copy_recipients
        , @reply_to = @l_reply_to
        , @subject = @l_subject
        , @body = @l_body
        , @query = @l_query
        , @query_result_separator = @l_query_result_separator
        , @query_result_no_padding = @l_query_result_no_padding
        , @attach_query_result_as_file = @l_attach_query_result_as_file
        , @query_attachment_filename = @l_query_attachment_filename
        , @append_query_error = @l_append_query_error;

END;

From what I can tell it looks like this line:

DECLARE @l_query nvarchar(500) = 'SELECT TOP(1) * FROM [Automation].[dbo].[Enquiry] ORDER BY [Id] DESC';

maybe blocking something or the trigger itself blocks that statement.

I’ve tried several things which no luck.

Please help!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T04:20:46+00:00Added an answer on June 9, 2026 at 4:20 am

    Wel you are in the middle of a transaction so at least that row is locked, then you send a mail, the mail is running a select top on the same table which you have a lock on…

    You could try nolock as losbear suggested, however seeing as the query you ae running is presumably meant to show the details of the record you’ve just inserted and you have inserted availble in your trigger, why bother with @query at all.

    Personally I’ve never liked the idea of sending a mail in the middle of my transaction. I’d rather queue the request, commit the transaction and then have some “service” do the mailing. That would be a fair bit more work though.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently use the following code to trigger an event from my Firefox Add-On.
Need help on this following code. the problem is it only trigger the last
I started with the following trigger in SqlServer 2000 ALTER TRIGGER DeleteTrigger ON [dbo].[WarrantyClaimsLineItems]
I have the following trigger First trigger: ALTER TRIGGER [dbo].[DIENSTLEISTUNG_Update] ON [dbo].[DIENSTLEISTUNG] INSTEAD OF
Could one help translating following sed command so it does the same on aix
Help me translate following block of the Haskell code. The run function produces text
Please help regarding the following issue. I have enabled the Block popup option in
Please help me with following, I have a database which contain strings ( e.g.
Please help with the following: I have an input file that is quite heterogeneous
Please help with the following error that I get with Spring Security 3.05 and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.