1

I am using the power shell to execute one of the stored procedure which has one of the parameter with the datatype sql_Variant and resided in the SSISDB (System stored procedure)

As sql_variant supports multi datatype I am passing int,string & boolean data types.

stored procedure executing fine when I pass the string data type. but not the int and boolean.

Procedure Name is

Catalog.Set_Object_Parameter_Value

It has one Parameter with the datatype SQL_Variant. Below is screen shot.

enter image description here

While Inputting value based of some condition I will get int/string/bool datatype.

How Can I Handle/Convert those value to Sql_Variant data type before input using Power-shell.

Currently my power-shell command something like below.

$procSignature = "EXEC [catalog].[set_object_parameter_value] @object_type,@folder_name,@project_name,@parameter_name,@parameter_value,@object_name";
                            $cmd = New-Object System.Data.SqlClient.SqlCommand;
                            $cmd.Connection = $catalogConnection;
                            $cmd.CommandText = $procSignature;
                            $cmd.Parameters.AddWithValue("@object_type", $Scope ) | Out-Null;
                            $cmd.Parameters.AddWithValue("@folder_name", $FolderName ) | Out-Null;
                            $cmd.Parameters.AddWithValue("@project_name", $ProjectName ) | Out-Null;
                            $cmd.Parameters.AddWithValue("@parameter_name", $ParmeterName ) | Out-Null;
                            $cmd.Parameters.AddWithValue("@parameter_value", $ParmeterValue ) | Out-Null;
                            $cmd.Parameters.AddWithValue("@object_name", $object ) | Out-Null;
Roshan Nuvvula
  • 803
  • 1
  • 8
  • 28
  • So what exactly is the error? I suppose the issue is with the stored procedure, *not* the powershell script. – marsze Feb 18 '19 at 12:32
  • Can you not use [string]$ParameterValue in place of $ParameterValue? – AdminOfThings Feb 18 '19 at 13:25
  • @marsze Since it is system stored procedure i don't think so it is an issue with stored procedure. – Roshan Nuvvula Feb 19 '19 at 02:11
  • @AdminOfThings - I got the following Error Message. Exception calling "ExecuteNonQuery" with "0" argument(s): "The data type of the input value is not compatible with the data type of the 'Boolean'." Exception calling "ExecuteNonQuery" with "0" argument(s): "The data type of the input value is not compatible with the data type of the 'Boolean'." Exception calling "ExecuteNonQuery" with "0" – Roshan Nuvvula Feb 19 '19 at 02:12

1 Answers1

0

I had exactly the same issue with exactly the same SP. Try this:

$cmd.Parameters.AddWithValue("@parameter_value", $ParameterValue -As $ParameterValue.GetType().Name) | Out-Null;
PLK
  • 389
  • 2
  • 13
  • It is not able to handle Boolean Values. – Roshan Nuvvula May 02 '19 at 07:37
  • 1
    That's true. In the end, I made the UI which feeds this have a drop-down for the parameter type too. It's too messy/impossible to deal with SQL variants in PowerShell and have things guessed correctly. – PLK May 04 '19 at 16:02