diff --git a/src/Microsoft.DotNet.Interactive.SqlServer/MsSqlKernel.cs b/src/Microsoft.DotNet.Interactive.SqlServer/MsSqlKernel.cs index 9c2e8cdc76..9571f7f1b2 100644 --- a/src/Microsoft.DotNet.Interactive.SqlServer/MsSqlKernel.cs +++ b/src/Microsoft.DotNet.Interactive.SqlServer/MsSqlKernel.cs @@ -48,11 +48,6 @@ public override async Task ConnectAsync() protected override string CreateVariableDeclaration(string name, object value) { - if (value is PasswordString ps) - { - value = ps.GetClearTextPassword(); - } - return $"DECLARE @{name} {MapToSqlDataType(name, value)} = {MapToSqlValueDeclaration(value)};"; static string MapToSqlDataType(string name, object value) @@ -92,10 +87,6 @@ protected override bool CanDeclareVariable(string name, object value, out string msg = default; try { - if (value is PasswordString) - { - return true; - } SqlMetaData.InferFromValue( value, name); diff --git a/src/Microsoft.DotNet.Interactive.SqlServer/ToolsServiceKernel.cs b/src/Microsoft.DotNet.Interactive.SqlServer/ToolsServiceKernel.cs index ba365599f5..692eb9b053 100644 --- a/src/Microsoft.DotNet.Interactive.SqlServer/ToolsServiceKernel.cs +++ b/src/Microsoft.DotNet.Interactive.SqlServer/ToolsServiceKernel.cs @@ -399,7 +399,14 @@ private string PrependVariableDeclarationsToCode(SubmitCode command, KernelInvoc foreach (var variableNameAndValue in _variables) { - var declareStatement = CreateVariableDeclaration(variableNameAndValue.Key, variableNameAndValue.Value); + var value = variableNameAndValue.Value; + + if (value is PasswordString ps) + { + value = ps.GetClearTextPassword(); + } + + var declareStatement = CreateVariableDeclaration(variableNameAndValue.Key, value); var displayStatement = declareStatement; @@ -442,6 +449,11 @@ private string PrependVariableDeclarationsToCode(SubmitCode command, KernelInvoc throw new ArgumentNullException(nameof(value), $"Sharing null values is not supported at this time."); } + if (value is PasswordString ps) + { + value = ps.GetClearTextPassword(); + } + if (!CanDeclareVariable(name, value, out string msg)) { throw new ArgumentException($"Cannot support value of Type {value.GetType()}. {msg}");