Skip to content

Commit

Permalink
Fixes #2305 - Enable Notebook Agent Jobs to succeed on named instances (
Browse files Browse the repository at this point in the history
#2306)

Adds in Default Parameter value for the ServerInstance parameter of Invoke-SqlCmd with the Agent tokens for the machine and the instance
  • Loading branch information
SQLDBAWithABeard authored Jul 12, 2024
1 parent 84ad774 commit 07ba144
Showing 1 changed file with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ $JobId = "$(ESCAPE_SQUOTE(JOBID))"
$StartTime = "$(ESCAPE_SQUOTE(STRTTM))"
$StartDate = "$(ESCAPE_SQUOTE(STRTDT))"
$JSONTable = "select * from notebooks.nb_template where job_id = $JobId"
# so that we can use Invoke-Sqlcmd with named instances lets set a variable to the host\instancename
$SqlInstance = '{0}\{1}' -f "$(ESCAPE_SQUOTE(MACH))", "$(ESCAPE_SQUOTE(INST))"
# so that every time we call Invoke-Sqlcmd we don't have to specify the server instance
$PSDefaultParameterValues = @{
"Invoke-SqlCmd:ServerInstance" = $SqlInstance
}
$sqlResult = Invoke-Sqlcmd -Query $JSONTable -Database $TargetDatabase -MaxCharLength 2147483647
$FirstNotebookError = ""
function ParseTableToNotebookOutput {
Expand Down Expand Up @@ -59,7 +65,7 @@ function ParseQueryErrorToNotebookOutput {
", State " + $QueryError.Exception.InnerException.State +
", Line " + $QueryError.Exception.InnerException.LineNumber +
"`r`n" + $QueryError.Exception.Message

$ErrorOutput = @{ }
$ErrorOutput["output_type"] = "error"
$ErrorOutput["traceback"] = @()
Expand Down

0 comments on commit 07ba144

Please sign in to comment.