2012-05-19 4 views
0

다음 코드는 W7, Serve2008에서 작동하지만 scriptblock이 작업으로 실행될 때 Server 2003에서 오류가 발생하지 않습니다.Server 2003의 PowerShell 작업에서 SQLConnection.open()이 실패 함

$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" 

내 작업 도메인의 일부 컴퓨터에서 스크립트를 테스트했습니다. 직접 실행은 어떤 컴퓨터에서도 문제가되지 않습니다. Windows Server 2003 SP 2에서 작업으로 실행이 실패합니다. open()이 작동하지 않거나 연결이 열리지 않는 경우 기본 시간 초과는 15 초입니다.

참고 : 이러한 서버의 작업 내에서 sqlcmd를 성공적으로 실행할 수 있습니다.

이 문제는 짧은 시간에 대체 할 수없는 일부 빌드 에이전트에서 발생합니다.

나는 서버 2003 SP 2

답변

0

이 때문에 CredSPP 및 자격 대표의 수와 함께 작동하는 솔루션이 필요합니다. Windows Server 2003에는 CredSSP 클라이언트 구성 요소 만 있고 서버 구성 요소는 없습니다. 따라서 Windows Server 2003 상자도 도메인 컨트롤러가 아니면 자격 증명 위임 nevers가 작동합니다.

+0

이 문제와 관련이 있는지 잘 모르겠습니다. 내가 열려있는 연결에 대한 SQL Server 인증을 사용하고 같은 자격 증명과 sqlcmd 작동합니다. –

+0

그러나 백그라운드 작업은 원격 인프라를 사용합니다. – ravikanth

+0

Invoke-Command -ScriptBlock에서 해당 코드를 실행 해보십시오. 당신은 직업과 같은 결과를 볼 수 있습니다! – ravikanth