I am trying to run an SSIS package through a stored procedure, but I am getting an Access is denied
error when I try to import a CSV.
I put the package inside a job and ran it and it worked as long as I used a proxy account. I am trying to replicate that proxy account to the stored procedure call without using xp_cmdshell
. I also ran this package inside Visual Studio and it ran smoothly.
My SSIS package is simple: It imports a CSV file from the network, converts the data to varchar
, and stores the data into a table.
Even my sysadmin was not able to successfully run the stored procedure.
My stored procedure looks like this:
ALTER PROCEDURE [dbo].[spImportFile]
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
DECLARE @execution_id bigint
EXEC SSISDB.CATALOG.create_execution
@folder_name = 'folder_name',
@project_name = 'project_name',
@package_name = 'package_name.dtsx',
@use32bitruntime = 1,
@execution_id = @execution_id output
EXEC SSISDB.CATALOG.start_execution @execution_id
END
My question is, how can I programmatically use a proxy user inside this stored procedure without using xp_cmdshell
?
UPDATE:
I am now trying to impersonate my proxy user thanks to billinkc, but now I am running into this error when I execute the SSIS package:
The current security context cannot be reverted. Please switch to the original database where 'Execute As' was called and try it again.
Here is my altered code:
ALTER PROCEDURE [dbo].[spImportFile]
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
EXECUTE AS LOGIN = 'domain\credentials'
DECLARE @execution_id bigint
EXEC SSISDB.CATALOG.create_execution
@folder_name = 'folder_name',
@project_name = 'project_name',
@package_name = 'package_name.dtsx',
@use32bitruntime = 1,
@execution_id = @execution_id output
EXEC SSISDB.CATALOG.start_execution @execution_id -- <<<< ERROR HERE!
REVERT
END
I successfully tested EXECUTE AS LOGIN
and REVERT
without start_execution
by looking into a system table I wouldn't usually have access to.