header1   header
header
header Register : : Login header
header
connector   connector
menuleft menuright
submenu   submenu
left
SQL query never completes in background job
Last Post 26 Jan 2010 12:41 PM by Chad Miller. 4 Replies.
Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
Ryan GreeleyUser is Offline
New Member
New Member
Posts:3
Avatar

--
26 Jan 2010 08:05 AM
    I have a command that I want to run against multiple SQL servers.  To make the script run quicker I'd like to use background jobs.  When I run the command outside of a job it completes and gives me the output I expect.  When I run the command inside of a job it gets stuck in a "running" state.

    This command runs fine:

    $Serverlist = 'server1','server2' 
    foreach ($Server in $ServerList) { 
       $con = "server=$Server;database=master;Integrated Security=sspi" 
       $cmd = "EXEC master.dbo.xp_msver" 
       $da = new-object System.Data.SqlClient.SqlDataAdapter ($cmd, $con) 
       $dt = new-object System.Data.DataTable 
       $da.fill($dt) 
       $dt 
     }


    However, this command creates the background jobs but they never complete

    $Serverlist = 'server1','server2' 
    foreach ($Server in $ServerList) { 
       Start-Job -ArgumentList $Server -ScriptBlock { 
          param ($Server) 
          $con = "server=$Server;database=master;Integrated Security=sspi" 
          $cmd = "EXEC master.dbo.xp_msver" 
          $da = new-object System.Data.SqlClient.SqlDataAdapter ($cmd, $con) 
          $dt = new-object System.Data.DataTable 
          $da.fill($dt) 
          $dt 
       }
    }
    Chad MillerUser is Offline
    Basic Member
    Basic Member
    Posts:160
    Avatar

    --
    26 Jan 2010 12:04 PM
    Having trouble reproducing issue. I ran both commands only changing server1 and server2 to my server names and both complete without issue. Are running Get-Job | Receive-Job to return the output? What's the output of Get-Job?
    Ryan GreeleyUser is Offline
    New Member
    New Member
    Posts:3
    Avatar

    --
    26 Jan 2010 12:18 PM
    Get-job gives me this:

    PS U:\> get-job

    Id Name State HasMoreData Location Command
    -- ---- ----- ----------- -------- -------
    1 Job1 Running True localhost ...
    3 Job3 Running True localhost ...

    Get-job | receive-job returns nothing:
    PS U:\> get-job | receive-job
    PS U:\>
    Ryan GreeleyUser is Offline
    New Member
    New Member
    Posts:3
    Avatar

    --
    26 Jan 2010 12:31 PM

    I found a workaround.  The script's background jobs don't complete when running from Powershell V2 on Windows XP. 

    I just tried running the script on Windows 2008 and it completed successfully.

    Ryan

    Chad MillerUser is Offline
    Basic Member
    Basic Member
    Posts:160
    Avatar

    --
    26 Jan 2010 12:41 PM
    Interesting, I would have thought of that. You may want to verify you have the RTM version of V2 on XP:

    http://support.microsoft.com/kb/968929

    Maybe file a connect bug if one doesn't already exist.

    You are not authorized to post a reply.


    Active Forums 4.3
    right
    footer   footer
    footer Sponsored by Quest Software • SAPIEN Technologies • Compellent • Microsoft Windows Server 2008 R2 footer
    footer   footer