Reputation: 365
If I hard code the values for @param_name, @param_value then the script works. However, If I use the following script, I get a "Cannot find the parameter because it does not exist" error. I tried many variations without success. The parameters are properly populated and have the correct data types.
declare @param_name as nvarchar(128), @param_value sql_variant
declare set_environment_params cursor for
select cast(name as nvarchar(128)) as name, value from internal.environment_variables
where environment_id=00
open set_environment_params
fetch next from set_environment_params
into @param_name, @param_value
while @@FETCH_STATUS=0
begin
EXEC [SSISDB].[catalog].[set_object_parameter_value] @object_type=20,
@parameter_name=@param_name,
@object_name=N'Test',
@folder_name=N'DevOps',
@project_name=N'Test',
@value_type=R,
@parameter_value=@param_value
fetch next from set_environment_params
into @param_name, @param_value
end
deallocate set_environment_params;
close set_environment_params;
GO
Upvotes: 0
Views: 3243
Reputation: 61269
set_object_parameter_value
is overloaded. If you want to set a Value, then specify the value in @parameter_value
If you want to set a reference to an environmental variable, then @parameter_value
is the name of the variable being referenced.
It's working for me, after
I have my project parameters defined as
In SSIS catalog, I created an environment called SOEnvironment
and populated it with 3 variables as such
DECLARE @var datetime = N'2018-01-02';
EXEC SSISDB.catalog.create_environment_variable
@variable_name = N'aDateTime'
, @sensitive = False
, @description = N''
, @environment_name = N'SOEnvironment'
, @folder_name = N'So'
, @value = @var
, @data_type = N'DateTime';
GO
DECLARE @var int = N'0';
EXEC SSISDB.catalog.create_environment_variable
@variable_name = N'anInt'
, @sensitive = False
, @description = N''
, @environment_name = N'SOEnvironment'
, @folder_name = N'So'
, @value = @var
, @data_type = N'Int32';
GO
DECLARE @var sql_variant = N'A';
EXEC SSISDB.catalog.create_environment_variable
@variable_name = N'aWideString'
, @sensitive = False
, @description = N''
, @environment_name = N'SOEnvironment'
, @folder_name = N'So'
, @value = @var
, @data_type = N'String';
GO
After transposing your last two statements (close, then deallocate the cursor), I clicked on Configure for the project and confirmed I have values connected to the environmental values
That looked odd to me and so I clicked in to see how SSMS does it. We have 3 options: Edit Value, use Default, Use Reference
When you explicitly supply a value, it shows as bold (aDateTime) When you use an environmental reference, it shows as underlined (aWideString) The Default is left in normal font (anInt)
So, I then looked at the generated SQL and the last argument should be
@parameter_value = @param_name
for environmental references.
Upvotes: 1