I want to execute set of un-contained stored procedures, as jobs, to see if there are any issues in the code after making the database as contained database. After some time, I want to see whether the stored procedures are successful or not. But, I see that instead of one job for a stored procedure, two jobs are getting created. How to avoid the creation of two jobs?
$unContainedSProcs = Import-Csv -Path C:\DFLog\UnContained_Parameterless_SPs.csv
$batchSize = 50
$currentCompletedIdx = 0
$jobIds = @()
$scriptToExecute = {
Param($storedProcToExecute)
Invoke-Sqlcmd -Query "Exec $storedProcToExecute" -ServerInstance "<<ServerInstance>>" -Database "<<Database>>" -QueryTimeout 120
}
while ($currentCompletedIdx -le $unContainedSProcs.Length) {
for ($i= 0; $i -le $batchSize; $i++) {
$job = Start-Job -Name $unContainedSProcs[$i].UnContainedSProcName -ScriptBlock $scriptToExecute -ArgumentList $unContainedSProcs[$i].UnContainedSProcName
$jobIds += $job.Id
++$currentCompletedIdx
}
}
When I see the jobs list, using Get-Job, I see two jobs:
+----+--------------+------------------+-----------+---------------+--------------+------------------------------+ | Id | Name | PSJobTypeName | State | HasMoreData | Location | Command | +----+--------------+------------------+-----------+---------------+--------------+------------------------------+ | 1 | dbo.SPName | BackgroundJob | Completed | True | localhost | param($storedProcToExe... | | 41 | Job41 | BackgroundJob | Completed | True | localhost | param($storedProcToExe... | +----+--------------+------------------+-----------+---------------+--------------+------------------------------+
Start-Job. i don't know why, tho. [blush] - Lee_DaileyGet-Job. Just to have the basics covered, I hope you have made sure that the other job is not from an earlier run, correct? You can doget-job | remove-job -forceto be sure. I triedStart-jobon aninvoke-sqlcmdpayload and only got 1 job. So this is hard for me to explain. - Sid