Problem: I'm unable to execute sp_send_mail
from a trigger on SSISDB objects.
Background: we use SSIS deployed to the SQL Server catalog and we're trying to place a trigger on the [internal].[projects]
table of SSISDB in order to email management when a deployment happens. We do not use Team Foundation services as we don't want to incur the overheard with our limited use of SSIS so we're trying to come up with creative ways around it.
We have database mail configured and working with no issues, except when we actually attempt a deployment which fires the trigger.
The error we get is:
Failed to deploy the project. Fix the problems and try again later.:The current transaction cannot be committed and cannot support operations that write to the log file. Roll back the transaction.
The EXECUTE permission was denied on the object 'sp_send_dbmail', database 'msdb', schema 'dbo'.
After exhaustive research, I've found the user account its being executed as "S-1-9-3-130423068-130423068-130423068-130423068" (id was changed but you get the idea). I've assigned all possible users in the system I can see to the DatabaseMailUserRole
so that they can e-mail however what I keep encountering is the error above or this one:
Failed to deploy the project. Fix the problems and try again later.:The current transaction cannot be committed and cannot support operations that write to the log file. Roll back the transaction.
The server principal "1-9-3-130423068-130423068-130423068-130423068." is not able to access the database "" under the current security context.
What I've learned more recently is this is a user without a login. Does anyone have any pointers or advice in how we can go about this? I've read somethings between stack overflow and other places on google, that we should create a login for that SID to be able to assign permissions. Any help would be greatly appreciated!
Trigger being executed
CREATE TRIGGER [internal].[package_deploy]
ON [internal].[projects]
FOR INSERT, UPDATE
AS
BEGIN
SET NOCOUNT ON;
DECLARE @body NVARCHAR(MAX) = N'';
DECLARE @subject NVARCHAR(100) = N'';
DECLARE @recipients NVARCHAR(100) = '';
DECLARE @profile_name NVARCHAR(100) = '';
DECLARE @rc INTEGER = 0;
SELECT @body += CHAR(13) + CHAR(10) + name + ' Project was deployed on: ' + CAST(last_deployed_time AS NVARCHAR(MAX))
+ CHAR(13) + CHAR(10) + ' for ticket(s): ' + description
FROM inserted;
SELECT @subject = name + ' Project Deployment Notification' FROM inserted;
SELECT @recipients = @recipients
SELECT @profile_name = @profile_name
IF EXISTS (SELECT 1 FROM inserted)
BEGIN
EXEC msdb.dbo.sp_send_dbmail
@recipients = @recipients,
@profile_name = @profile_name,
@subject = @subject,
@body = @body;
END
END
GO