0

The following code seems works for me on W7, Serve2008 but fails fails on Server 2003 when the scriptblock is run as job.

$scriptblock = [scriptblock]::Create('
$DestinationConnectionString_sql = "Data Source=<myserver>;Initial Catalog=<mydatabase>;User Id=sa;Password=<sapassword>"
$destConnection  = New-Object System.Data.SqlClient.SQLConnection($DestinationConnectionString_sql)
"    Before Open Statement Connection State $($destConnection.State)"
$destConnection.open()
"    After Open Statement Connection State $($destConnection.State)"
$destConnection.close()
')

"--- direct call work on Server 2003 ---"
& $scriptblock

"--- call in PowerShell Job faills on Server 2003 ---"
Get-Job | remove-job -force

$start = Get-date
$job1 = (Start-job $scriptblock).id
"    started"
Wait-Job -id $job1  -timeout 30 | Out-Null
if ((Get-job -id $job1).state -eq 'Running')
{
    Stop-job -id $job1
} 
"    Job State: $((Get-Job).state)"

Receive-job -id $job1
$state1 = (Get-job -id $job1).State
$dauer1 = ((get-date) - $start).Totalseconds
"    Time spent in job: $dauer1"

I have tested the script with some machines in my working domain. Direct execution is no problem on any machine. Execution as job on Windows Server 2003 sp 2 fails. Neither the default timeout of 15 secs for open() not working nor the connection opening.

Note: I can run sqlcmd successfully within jobs on these servers.

The problem occurs on some build agents, which can't be replaced in short time.

I need a solution which works with Server 2003 sp 2.

Gaffi
  • 4,307
  • 8
  • 43
  • 73
bernd_k
  • 11,558
  • 7
  • 45
  • 64

1 Answers1

0

This could be because of CredSPP and credential delegation. Windows Server 2003 has only the CredSSP client component and no server component. So, the credential delegation nevers works there unless the Windows Server 2003 box is also a domain controller.

ravikanth
  • 24,922
  • 4
  • 60
  • 60