I have an activated procedure for a service broker queue that queries a linked server. I have signed the procedure using the method found here. However, I continuously see the following message in the sql server logs:
The activated proc '[dbo].[TestProc]' running on queue 'DBName.dbo.TestReceiveQueue' output the following: 'Access to the remote server is denied because the current security context is not trusted.'
The strange thing is that I have several different activated procedures in the same database, signed by the same certificate, that also do linked server queries, and work fine. For some reason, this procedure refuses to.
Here's some code to (mostly) reproduce the problem. I've created the certificate and associated login already.
CREATE PROCEDURE TestProc
WITH EXECUTE AS OWNER
AS
BEGIN
SET NOCOUNT ON;
DECLARE #convHandle UNIQUEIDENTIFIER;
DECLARE #msgTypeName SYSNAME;
DECLARE #status TINYINT;
DECLARE #srvName NVARCHAR(512);
DECLARE #srvConName NVARCHAR(256);
DECLARE #msgTypeValidation AS NCHAR(2);
DECLARE #msgBody NVARCHAR(256);
DECLARE #cmd AS NVARCHAR(50);
RECEIVE TOP(1)
#convHandle = conversation_handle,
#msgTypeName = message_type_name,
#status = status,
#srvName = service_name,
#srvConName = service_contract_name,
#msgTypeValidation = validation,
#msgBody = CAST(message_body AS NVARCHAR(256))
FROM TestReceiveQueue;
--SELECT #convHandle, #msgBody
IF (##ROWCOUNT != 0)
BEGIN
SELECT * FROM openquery(LINKEDSERVERNAME, 'SELECT * FROM LINKEDSERVERDB.SCHEMA.TABLE')
END CONVERSATION #convHandle
END
END
GO
CREATE MESSAGE TYPE [TestMessageType] VALIDATION = NONE;
CREATE CONTRACT TestContract (TestMessageType SENT BY INITIATOR)
CREATE QUEUE [dbo].[TestReceiveQueue] With STATUS = ON, RETENTION = OFF, ACTIVATION (STATUS = ON, PROCEDURE_NAME = [dbo].[TestProc], MAX_QUEUE_READERS = 1, EXECUTE AS OWNER ), POISON_MESSAGE_HANDLING (STATUS = OFF) ON [PRIMARY]
CREATE QUEUE [dbo].[TestSendQueue] WITH STATUS = ON, RETENTION = OFF, POISON_MESSAGE_HANDLING (STATUS = OFF) ON [PRIMARY]
CREATE SERVICE [TestReceiveService] ON QUEUE [dbo].[TestReceiveQueue] (TestContract)
CREATE SERVICE [TestSendService] ON QUEUE [dbo].[TestSendQueue] (TestContract)
Drop Procedure TestProc
ADD SIGNATURE TO OBJECT::[TestProc]
BY CERTIFICATE [ServiceBrokerProcsCert]
WITH PASSWORD = 'PASSWORDHERE'
GO
Is there any way I can debug this further, to figure out why I'm getting this error? I've tried ssbdiagnose on the conversation and there aren't any configuration errors. I also tried logging the CURRENT_USER inside the activated sproc which came back as dbo.
When I mark the database as trustworthy, it works, of course (but that's what I'm trying to avoid).
If database is TRUSTWORTHY OFF procedure will run only in context of signing user, not its OWNER as you expect.
Assign linked server privileges to user assiociated with ServiceBrokerProcsCert, it is right user in which context signed activation procedure runs.
Related
I have created a service Broker which is executing through Queue formed with the help of Trigger on a table.
I have to call another Database's Stored Procedure/Function from my current database's Queue_Procedure. And when trying to execute it, I am getting below error.
The activated proc '[dbo].[spGenerateProc_Test_RJ]' running on queue
'FirstDatabase.dbo.TestQueue_Test_RJ' output the following: 'The
server principal "sa" is not able to access the database
"SecondDatabase" under the current security context.'
Below is all query in steps I am using to create Service broker Queue and use it.
--Step 1:
Use FirstDatabaseName;
ALTER DATABASE FirstDatabaseName SET ENABLE_BROKER WITH ROLLBACK IMMEDIATE;
--Step 2:
CREATE TABLE PriceData_auditlog_Test_RJ
(
xmlstring xml
)
GO
CREATE PROCEDURE [dbo].[spGenerateProc_Test_RJ]
WITH EXECUTE AS CALLER
AS
BEGIN
DECLARE #message_type varchar(100)
DECLARE #dialog uniqueidentifier, #message_body XML;
WHILE (1 = 1)
BEGIN -- Receive the next available message from the queue
WAITFOR (
RECEIVE TOP(1) #message_type = message_type_name,
#message_body = CAST(message_body AS XML),
#dialog = conversation_handle
FROM dbo.TestQueue_Test_RJ
), TIMEOUT 500
IF (##ROWCOUNT = 0 OR #message_body IS NULL)
BEGIN
BREAK
END
ELSE
BEGIN
--process xml message here...
INSERT INTO PriceData_auditlog_Test_RJ values(#message_body)
SELECT BlobData.dbo.Get_BlobTagsCount_Test_RJ()
END
END CONVERSATION #dialog
END
END
--step 3: Create Message Type
CREATE MESSAGE TYPE TestMessage_Test_RJ
AUTHORIZATION dbo
VALIDATION = WELL_FORMED_XML;
--step 4: Create Contract
CREATE CONTRACT TestContract_Test_RJ
AUTHORIZATION dbo
(TestMessage_Test_RJ SENT BY INITIATOR);
-- step 5: Create Queue
CREATE QUEUE dbo.TestQueue_Test_RJ WITH STATUS=ON, ACTIVATION
(STATUS = ON, MAX_QUEUE_READERS = 7,
PROCEDURE_NAME = [dbo].[spGenerateProc_Test_RJ], EXECUTE AS N'dbo');
-- step 6: Create Service Initiator
CREATE SERVICE TestServiceInitiator_Test_RJ
AUTHORIZATION dbo
ON QUEUE dbo.TestQueue_Test_RJ (TestContract_Test_RJ);
--step 7: Create target Service
CREATE SERVICE [TestServiceTarget_Test_RJ]
AUTHORIZATION dbo
ON QUEUE dbo.TestQueue_Test_RJ (TestContract_Test_RJ);
--Step 8: CREATE Trigger on FirstDatabase table
CREATE TRIGGER [dbo].[Trg_PriceData_Update_Test_RJ]
ON FirstDatabaseName.dbo.Price
FOR UPDATE
AS
BEGIN
SET NOCOUNT ON;
DECLARE #MessageBody XML
--get relevant information from inserted/deleted and convert to xml message
SET #MessageBody = (SELECT ProductID FROM inserted FOR XML AUTO)
If (#MessageBody IS NOT NULL)
BEGIN
SELECT #MessageBody
DECLARE #Handle UNIQUEIDENTIFIER;
BEGIN DIALOG CONVERSATION #Handle
FROM SERVICE [TestServiceInitiator_Test_RJ]
TO SERVICE 'TestServiceTarget_Test_RJ'
ON CONTRACT [TestContract_Test_RJ]
WITH ENCRYPTION = OFF;
SEND ON CONVERSATION #Handle
MESSAGE TYPE [TestMessage_Test_RJ](#MessageBody);
END
END
GO
--Update statement to fire trigger which executes Service Broker Queue
Update FirstDatabaseName.dbo.Price
SET Price=141.833
WHERE ID=1408166
I have also followed steps mentioned in Blog link
But still I am getting same error.
The activated proc '[dbo].[spGenerateProc_Test_RJ]' running on queue 'FirstDatabase.dbo.BundleQueue_Test_RJ' output the following: 'The server principal "sa" is not able to access the database "SecondDatabase" under the current security context.'
Edit:
By referring link, Below are the steps I have used for creating certificate to use function/Procedure in other database.
Source db configuration
--Certificate Installation Start
-- Create a certificate with a private key
USE [FirstDatabseName]
GO
CREATE CERTIFICATE [spGenerateBundleProcAudit_Test_RJ]
ENCRYPTION BY PASSWORD = 'Password#1234'
WITH SUBJECT = 'spGenerateBundleProcedure Signing for audit certificate';
GO
--Sign the procedure with the certificate’s private key
ADD SIGNATURE TO OBJECT::[spGenerateBundleProc_Test_RJ]
BY CERTIFICATE [spGenerateBundleProcAudit_Test_RJ]
WITH PASSWORD = 'Password#1234';
GO
--Drop the private key. This way it cannot be
-- used again to sign other procedures.
ALTER CERTIFICATE [spGenerateBundleProcAudit_Test_RJ]
REMOVE PRIVATE KEY;
GO
--We must backup to a file and create
--the certificate in [master] from this file
BACKUP CERTIFICATE [spGenerateBundleProcAudit_Test_RJ]
TO FILE = 'C:\spGenerateBundleProcAudit2_Test_RJ.CER';
GO
Target db configuration
USE [SecondDatabseName]
GO
--DROP CERTIFICATE [spGenerateBundleProcAudit_Test_RJ]
CREATE CERTIFICATE [spGenerateBundleProcAudit_Test_RJ]
FROM FILE = 'C:\spGenerateBundleProcAudit2_Test_RJ.CER';
GO
--DROP USER [spGenerateBundleProcAudit_Test_RJ]
CREATE USER [spGenerateBundleProcAudit_Test_RJ]
FROM CERTIFICATE [spGenerateBundleProcAudit_Test_RJ];
GO
--‘AUTHENTICATE’ permission is required for all other permissions to take effect
GRANT AUTHENTICATE TO [spGenerateBundleProcAudit_Test_RJ];
GRANT EXECUTE ON [Get_BlobTagsCount_Test_RJ] TO [spGenerateBundleProcAudit_Test_RJ];
GO
--Enable back the disabled ‘SessionsService’ queue
ALTER QUEUE dbo.TestQueue_Test_RJ WITH STATUS=ON
GO
--Certificate Installation End
I've been able to setup my Visual Studio (2019) Database Project up and using database references fine for tables, stored procedures, views, etc. They all seem to match up fine with the schema I've imported. However, I can't seem to avoid errors when it comes to referencing the same database's contracts, types, services, etc. When I reference the target database's service I have no issue (I assume this is because it accepts basic NVARCHAR strings versus a strongly-typed schema.
I've got the following example that just sends a message to another database's service. I get the error: "SQL71502: Procedure: [dbo].[z_Queue_SendMessage] has an unresolved reference to object [#VariableName]" with #VariableName being all of the following: (#RequestMessageType, #BasicContract, #InitiatorService)
CREATE PROCEDURE [dbo].[z_Queue_SendMessage]
#ProcedureName VARCHAR(1000) = 'Procedure',
#SubProcedureName VARCHAR(500) = 'SO',
#ProcedureType VARCHAR(200) = 'Delete',
#Inserted AS XML = NULL,
#Deleted AS XML = NULL
AS
DECLARE #InitDlgHandle UNIQUEIDENTIFIER;
DECLARE #RequestMsg NVARCHAR(MAX);
DECLARE #Message XML;
DECLARE #RequestMessageType NVARCHAR(100) = '//$(WebDb)' + N'/Queue/RequestMessage'
DECLARE #InitiatorService NVARCHAR(100) = '//$(WebDb)' + N'/Queue/InitiatorService'
DECLARE #BasicContract NVARCHAR(100) = '//$(WebDb)' + N'/Queue/BasicContract'
DECLARE #TargetService NVARCHAR(100) = '//$(WebDb)' + N'/Queue/TargetService'
BEGIN TRANSACTION;
BEGIN DIALOG #InitDlgHandle
FROM SERVICE [#InitiatorService] --Here
TO SERVICE #TargetService
ON CONTRACT [#BasicContract] --Here
WITH
ENCRYPTION = OFF;
SET #Message = (SELECT
ProcedureName = #ProcedureName,
SubProcedureName = #SubProcedureName,
ProcedureType = #ProcedureType,
Inserted = #Inserted,
Deleted = #Deleted
FOR XML PATH('Request'));
SEND ON CONVERSATION #InitDlgHandle
MESSAGE TYPE [#RequestMessageType] --Here
(#Message);
SELECT #Message AS SentRequestMsg;
COMMIT TRANSACTION;
Is there any way to format this so I don't get the error message without using Dynamic SQL? It defeats the purpose if I can't confirm it matches the database schema by suppressing errors or using dynamic SQL instead.
This works
BEGIN DIALOG CONVERSATION #Handle
FROM SERVICE #SvcName
TO SERVICE #TargetSvc, 'CURRENT DATABASE'
WITH ENCRYPTION = OFF
Try not quoting both #InitiatorService, #BasicContract and #RequestMessageType -- this just makes no sense.
I ended up having to import the creation scripts/files into my Visual Studio Database Project to get this all to work properly without giving me syntax errors.
I tried extracting the DACPAC with "Include application-scoped objects only" unchecked and "include extended properties" checked but was still getting the same issues I had before.
I added individual SQL items to my project for messages, services and contracts. Examples:
Service:
CREATE SERVICE [//Web/Queue/InitiatorService]
ON QUEUE DataQueue;
Contract:
CREATE CONTRACT [//Web/Queue/BasicContract]
(
[//Web/Queue/RequestMessage] SENT BY INITIATOR,
[//Web/Queue/ReplyMessage] SENT BY TARGET
)
Message Types:
CREATE MESSAGE TYPE [//Web/Queue/ReplyMessage]
VALIDATION = WELL_FORMED_XML;
CREATE MESSAGE TYPE [//Web/Queue/RequestMessage]
VALIDATION = WELL_FORMED_XML;
That allowed me to conform to the database schema still and avoid future errors. I did still reference the target service with a SQLCMD variable so I can use the same name except for the service in development vs production environments. Here's my stored procedure for sending messages now:
CREATE PROCEDURE [dbo].[z_Queue_SendMessage]
#ProcedureName VARCHAR(1000) = 'Procedure',
#SubProcedureName VARCHAR(500) = 'SO',
#ProcedureType VARCHAR(200) = 'Delete',
#Inserted AS XML = NULL,
#Deleted AS XML = NULL
AS
DECLARE #InitDlgHandle UNIQUEIDENTIFIER;
DECLARE #RequestMsg NVARCHAR(MAX);
DECLARE #Message XML;
DECLARE #TargetService NVARCHAR(100) = N'//$(WebDb)/Queue/TargetService'
BEGIN TRANSACTION;
BEGIN DIALOG #InitDlgHandle
FROM SERVICE [//Web/Queue/InitiatorService]
TO SERVICE #TargetService
ON CONTRACT [//Web/Queue/BasicContract]
WITH
ENCRYPTION = OFF;
SET #Message = (SELECT
ProcedureName = #ProcedureName,
SubProcedureName = #SubProcedureName,
ProcedureType = #ProcedureType,
Inserted = #Inserted,
Deleted = #Deleted
FOR XML PATH('Request'));
SEND ON CONVERSATION #InitDlgHandle
MESSAGE TYPE [//Web/Queue/RequestMessage]
(#Message);
SELECT #Message AS SentRequestMsg;
COMMIT TRANSACTION;
Service Broker is working only for the first time.
I am new to service broker and learning the same. Doing it for the first time.
I suspected that it is working only for the first time so i changed the name of the service/contract and queue and again tried to test it out it worked that also once it worked. Again I changed the name and tried again it worked once only.
Service Broker Contract/Service/Queue creation
IF NOT EXISTS( SELECT '*'
FROM sys.service_contracts
WHERE NAME = N'TESTContract1234')
BEGIN
CREATE CONTRACT TESTContract1234
([http://schemas.microsoft.com/SQL/ServiceBroker/DialogTimer] SENT BY INITIATOR)
END
IF NOT EXISTS( SELECT '*'
FROM sys.service_queues
WHERE NAME = N'TEST_SCHEDULEDJOBQUEUE1234')
BEGIN
create QUEUE TEST_SCHEDULEDJOBQUEUE1234
WITH STATUS = on,
ACTIVATION (
PROCEDURE_NAME = testing1_sp,
MAX_QUEUE_READERS = 1, -- we expect max 20 jobs to start simultaneously
EXECUTE AS 'dbo' );
END
IF NOT EXISTS( SELECT '*'
FROM sys.services
WHERE NAME = N'//TESTJOBSERVICE1234')
BEGIN
CREATE SERVICE [//TESTJOBSERVICE1234]
AUTHORIZATION dbo
ON QUEUE TEST_SCHEDULEDJOBQUEUE1234 (TESTContract1234)
END
SP which gets executed in the Queue
create table testing1
(
descr varchar(255),
seqno int identity(1,1),
currtime date
)
create procedure testing1_sp
as
begin
set nocount on
insert into testing1(descr,currtime) values('Service Broker Sample',getdate())
set nocount off
end
Script used for Testing
declare #ConversationHandle UNIQUEIDENTIFIER ,#TimeoutInSeconds udd_int
SELECT #TimeoutInSeconds = DATEpart(s, dbo.RES_Getdate(0))--, #FirstRunOn);
BEGIN DIALOG CONVERSATION #ConversationHandle
FROM SERVICE [//TESTJOBSERVICE1234]
TO SERVICE '//TESTJOBSERVICE1234',
'CURRENT DATABASE'
ON CONTRACT TESTContract1234
WITH ENCRYPTION = OFF;
At the database level, service broker is enabled I checked the same using sys.databases catalog view column name is_broker_enabled.
In sys.conversation_endpoints catalog view one entry is available and state_desc for the same is "STARTED_OUTBOUND"
Please help me debug the issue and understand where I'm making mistake.
Thanks in advance.
I am experiencing poison messages and I am not sure why.
My broker setup looks like this:
CREATE MESSAGE TYPE
[//DB/Schema/RequestMessage]
VALIDATION = WELL_FORMED_XML;
CREATE MESSAGE TYPE
[//DB/Schema/ReplyMessage]
VALIDATION = WELL_FORMED_XML;
CREATE CONTRACT [//DB/Schema/Contract](
[//DB/Schema/RequestMessage] SENT BY INITIATOR,
[//DB/Schema/ReplyMessage] SENT BY TARGET
)
CREATE QUEUE Schema.TargetQueue
CREATE SERVICE [//DB/Schema/TargetService]
ON QUEUE Schema.TargetQueue (
[//DB/Schema/Method3Contract]
)
CREATE QUEUE Schema.InitiatorQueue
CREATE SERVICE [//DB/Schema/InitiatorService]
ON QUEUE Schema.InitiatorQueue
Then I have my internal activation procedure:
CREATE PROCEDURE Schema.Import
AS
DECLARE #RequestHandle UNIQUEIDENTIFIER;
DECLARE #RequestMessage VARCHAR(8);
DECLARE #RequestMessageName sysname;
WHILE (1=1)
BEGIN
BEGIN TRANSACTION;
WAITFOR (
RECEIVE TOP(1)
#RequestHandle = conversation_handle,
#RequestMessage = message_body,
#RequestMessageName = message_type_name
FROM
Schema.TargetQueue
), TIMEOUT 5000;
IF (##ROWCOUNT = 0)
BEGIN
COMMIT TRANSACTION;
BREAK;
END
EXEC Schema.ImportStep1 #ID = #RequestMessage;
--EXEC Schema.ImportStep2 #ID = #RequestMessage;
END CONVERSATION #RequestHandle;
COMMIT TRANSACTION;
END
My activation is enabled by:
ALTER QUEUE Schema.TargetQueue
WITH
STATUS = ON,
ACTIVATION
( STATUS = ON,
PROCEDURE_NAME = Schema.Import,
MAX_QUEUE_READERS = 10,
EXECUTE AS SELF
)
I initiate this process with this stored procedure
CREATE PROCEDURE Schema.ImportStart
AS
BEGIN
DECLARE #ID VARCHAR(8);
DECLARE Cursor CURSOR FOR
SELECT ID FROM OtherDatabase.OtherSchema.ImportTable
EXCEPT
SELECT ID FROM Table
OPEN Cursor;
FETCH NEXT FROM Cursor INTO #ID;
WHILE ##FETCH_STATUS = 0
BEGIN
DECLARE #InitiateHandle UNIQUEIDENTIFIER;
DECLARE #RequestMessage VARCHAR(8);
BEGIN TRANSACTION;
BEGIN DIALOG
#InitiateHandle
FROM SERVICE
[//DB/Schema/InitiatorService]
TO SERVICE
N'//DB/Schema/TargetService'
ON CONTRACT
[//DB/Schema/Contract]
WITH
ENCRYPTION = OFF;
SELECT #RequestMessage = #ID;
SEND ON CONVERSATION
#InitiateHandle
MESSAGE TYPE
[//DB/Schema/RequestMessage]
(#RequestMessage);
COMMIT TRANSACTION;
FETCH NEXT FROM Cursor INTO #ID;
END
CLOSE Cursor;
DEALLOCATE Cursor;
END
So how this should work is:
I execute ImportStart
A message for each ID gets generated
Internal activation makes Import steps execute
Instead, I get poison messaging and the queue becomes disabled.
If however,
I I set Schema.TargetQue Activation to OFF
EXEC schema.ImportStart
EXEC schema.Import manually
It works fine.
Any insights anyone?
Well:
Your message types are defined as well_formed_xml, yet you send varchar(8) as a message body. Does it really work?
You use [//DB/Schema/Method3Contract] for the target queue, but do not define it. A misspelling, most likely.
You specify EXECUTE AS SELF in the queue activation. BOL says some mystical thing about this case:
SELF
Specifies that the stored procedure executes as the current user. (The database principal executing this ALTER QUEUE statement.)
I'm not really sure I understand the quoted statement, because it apparently contradicts with your experience. If it would be your user account, everything should have been fine, because you seem to have all permissions necessary to do the job.
So, just in case - who is the owner of the Schema schema? What permissions does this principal possess? And, if it's not you, who executes the alter queue statement (and why)?
Without access to logs, it's significantly more difficult to diagnose the problem, but I would start with creating a new user account with permissions identical to yours, setting it the owner of the Schema schema and then slowly working it down, revoking unnecessary permissions until it breaks. Assuming, of course, it will work at all.
I have an INSERT trigger on a table that simply executes a job.
Example:
CREATE TABLE test
(
RunDate smalldatetime
)
CREATE TRIGGER StartJob ON test
AFTER INSERT
AS
EXEC msdb.dbo.sp_start_job 'TestJob'
When I insert a record to this table, the job is fired of without any issue. There are a few people, however, that have lower permissions than I do (db_datareader/db_datawriter on the database only); they are able to insert a record to the table, but the trigger does not fire.
I am a SQL Server novice and I was under the impression that users did not need elevated permissions to fire off a trigger (I thought that was one of the big benefits!). Is this a permission issue at the trigger level, or at the job level? What can I do to get around this limitation?
The trigger will execute in the context of the caller, which may or may not have the permissions to access msdb. That seems to be your problem. There are a few ways to extend these permissions using Execute As; they are greatly detailed in this link
Use impersonation within trigger:
CREATE TRIGGER StartJob ON test
with execute as owner
AFTER INSERT
AS
EXEC msdb.dbo.sp_start_job 'TestJob'
And set database to trustworthy (or read about signing in above link):
alter database TestDB set trustworthy on
Another way to go (depending on what operations the agent job performs) would be to leverage a Service Broker queue to handle the stored procedure activation. Your users' context would simply call to Send On the queue while, in an asynchronous process SvcBroker would activate a stored procedure which executed in context of higher elevated user. I would opt for this solution rather than relying on a trigger calling an agent job.
I wanted to test the call to Service Broker, so I wrote this simple test example. Instead of calling an SSIS package I simply send an email, but it is very similar to your situation. Notice I use SET TRUSTWORTHY ON at the top of the script. Please read about the implications of this setting.
To run this sample you will need to substitute your email profile info below, <your_email_address_here>, etc.
use Master;
go
if exists(select * from sys.databases where name = 'TestDB')
drop database TestDB;
create database TestDB;
go
alter database TestDB set ENABLE_BROKER;
go
alter database TestDB set TRUSTWORTHY ON;
use TestDB;
go
------------------------------------------------------------------------------------
-- create procedure that will be called by svc broker
------------------------------------------------------------------------------------
create procedure dbo.usp_SSISCaller
as
set nocount on;
declare #dlgid uniqueidentifier;
begin try
-- * figure out how to start SSIS package from here
-- for now, just send an email to illustrate the async callback
;receive top(1)
#dlgid = conversation_handle
from SSISCallerQueue;
if ##rowcount = 0
begin
return;
end
end conversation #dlgid;
exec msdb.dbo.sp_send_dbmail
#profile_name = '<your_profile_here>',
#importance = 'NORMAL',
#sensitivity = 'NORMAL',
#recipients = '<your_email_address_here>',
#copy_recipients = '',
#blind_copy_recipients = '',
#subject = 'test from ssis caller',
#body = 'testing',
#body_format = 'TEXT';
return 0;
end try
begin catch
declare #msg varchar(max);
select #msg = error_message();
raiserror(#msg, 16, 1);
return -1;
end catch;
go
------------------------------------------------------------------------------------
-- setup svcbroker objects
------------------------------------------------------------------------------------
create contract [//SSISCallerContract]
([http://schemas.microsoft.com/SQL/ServiceBroker/DialogTimer] sent by initiator)
create queue SSISCallerQueue
with status = on,
activation (
procedure_name = usp_SSISCaller,
max_queue_readers = 1,
execute as 'dbo' );
create service [//SSISCallerService]
authorization dbo
on queue SSISCallerQueue ([//SSISCallerContract]);
go
return;
-- usage
/*
-- put a row into the queue to trigger the call to usp_SSISCaller
begin transaction;
declare #dlgId uniqueidentifier;
begin dialog conversation #dlgId
from service [//SSISCallerService]
to service '//SSISCallerService',
'CURRENT DATABASE'
on contract [//SSISCallerContract]
with encryption = off;
begin conversation timer (#dlgId)
TIMEOUT = 5; -- seconds
commit transaction;
*/
It would be permissions at the job level. You can possibly assign those users the SQLAgentReaderRole in MSDB to be able to start a job, considering that they would be added to a group that owned the job. If they are not in a group which owns the job, it gets more difficult.