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

  • SEARCH
  • Home
  • 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 8070487
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T13:24:36+00:00 2026-06-05T13:24:36+00:00

I have a simple trigger on INSERT ALTER TRIGGER [dbo].[SendErrorEmail] ON [dbo].[tblNewErrorLog] FOR INSERT

  • 0

I have a simple trigger on INSERT

ALTER TRIGGER [dbo].[SendErrorEmail]
   ON  [dbo].[tblNewErrorLog]
   FOR INSERT
AS 
BEGIN   


    EXEC msdb.dbo.sp_send_dbmail 
        @profile_name='myprofile',
        @recipients='me@me.com',
        @subject='error in the database',
        @body = 'check it out'

END
  • If I manually add a row using Management Studio, everything is fine, row added email sent.
  • If an error is logged via the service, nothing. No email, no new row.
  • If I remove the trigger – things work as expected, row added.
  • If I keep the trigger, but remove the email SP, its ok. New row added.

So, the error is obviously something to do with the email, maybe security? I have tried logging in the the credentials used by the service to connect to the DB, and It works if I add a row manually.

I am also a bit worried that even if the email doesn’t sent, the insert fails, why is that?

Thoughts on where to start troubleshooting this are most welcome.

Thanks!

Edits:
Removed try catch from code
general Tidy up

  • 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-05T13:24:38+00:00Added an answer on June 5, 2026 at 1:24 pm

    The trigger is executing in a context that does not have EXECUTE permission to the msdb.dbo.sp_send_dbmail procedure. Most likely you are falling into the constrained EXECUTE AS sandboxing, see Understanding Execution Context. This would manifest exactly as you describe the problem: it works from SSMS but not in your application.

    See Call a procedure in another database from an activated procedure for an example how to use code signing to grant execute permission to code running in EXECUTE AS context sandbox.

    If the code is not running under EXECUTE As then is just a simple matter of permissions. You can either grant [msdb] access and EXECUTE permission on sp_send_dbmail to the service account that you application uses, or you can again use code signing as above.

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

Sidebar

Related Questions

I have a simple question. Ive got a trigger to insert the values into
I have problem with creating a simple MySQL trigger in C#. I'm using StringBuilder
I have simple SSIS package which reads data from flat file and insert into
I have a trigger AFTER INSERT inside which I must update the value of
I work with SQL Server 2008 R2 I have a simple trigger CREATE TRIGGER
I have a simple trigger which pulls data from the lead object and places
I have a very simple trigger. I cretaed it from Toad for mysql tool
I have a simple INSERT query where I need to use UPDATE instead when
I have an INSERT trigger on a table that simply executes a job. Example:
I have a pretty simple trigger: CREATE OR REPLACE FUNCTION f_log_datei() RETURNS TRIGGER AS

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.