I'm working with SQL Server 2012 Express.
I'm using Service Broker to run a stored procedure asynchronously.
The activation procedure has to access another database to execute another stored procedure. This is the code:
CREATE PROCEDURE [dbo].[GetNewCodes]
@gintNewCodes bigint,
@presNewCodes tinyint,
@levelNewCodes bigint,
@quantityNewCodes smallint
AS
-- Get new codes from INCIC database.
DECLARE @return_value int,
@xmlGenerated xml,
@xmlString NVARCHAR(MAX)
SET NOCOUNT ON;
-- Set that this stored procedure is running
update dbo.RunningSPs with (serializable) set conf_value = 1
where sp_name = N'GetNewCodes'
if @@rowcount = 0
begin
insert dbo.RunningSPs(sp_name, conf_value) values (N'GetNewCodes', 1)
end
EXEC @return_value = [INCIC].[dbo].[ReadCodeBuffer]
@gint = @gintNewCodes,
@pres = @presNewCodes,
@level = @levelNewCodes,
@quantity = @quantityNewCodes,
@xmlGenerated = @xmlGenerated OUTPUT
SET @xmlString = cast(@xmlGenerated as nvarchar(max))
-- Process these new codes on TRZ.
EXEC dbo.ProcessCodes @XmlString = @xmlString
-- Update that we are not running this procedure any more.
update dbo.RunningSPs with (serializable) set conf_value = 0
where sp_name = N'GetNewCodes'
if @@rowcount = 0
begin
insert dbo.RunningSPs(sp_name, conf_value) values (N'GetNewCodes', 0)
end
The problem is here: [INCIC].[dbo].[ReadCodeBuffer]
, and the error message is:
Error: 50000
Unrecoverable error in procedure GetNewCodes: 916: The server principal "sa" is not able to access the database "INCIC" under the current security context.
I have followed this tutorial to implement Service, queue and activation stored procedure.
How can I fix this problem?