sql-serverpolyglot.net-interactive

How to construct connect mssql command with variable in Polyglot Notebook


How to construct a magic connect command with variable? For example with a variable value as myserver.

#!value --name sqlserver myserver

#!share sqlserver --from value string sqlconnstr = $"Server={sqlserver}; Initial Catalog=mydb; Persist Security Info=False; Integrated Security=true;"; #!connect mssql --kernel-name mydb sqlconnstr

This doesn't work.

Expecting to have something similar that can take a variable like this static command that works,

#!connect mssql --kernel-name mydb "Server=myserver; Initial Catalog=mydb; Persist Security Info=False; Integrated Security=true;"


Solution

  • Received clarification from .net interactive contributor.

    Values from other kernels can be inlined with the syntax @kernelName:variableName so in your scenario it could look something like this:

    #!connect mssql --kernel-name mydb @csharp:sqlconnstr