header
header Register : : Login header
header
divider
menuleft
menuright
submenu
left

We have a new sponsor!  Introducting Pragma Systems.  See the home page for details.

SQL query never completes in background job
Last Post 26 Jan 2010 08:41 PM by cmille19. 4 Replies.
Printer Friendly
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
RyanGreeleyUser is Offline
New Member
New Member
Posts:3
Avatar

--
26 Jan 2010 04:05 PM  
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 
   }
}
cmille19User is Offline
New Member
New Member
Posts:65
Avatar

--
26 Jan 2010 08: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?
RyanGreeleyUser is Offline
New Member
New Member
Posts:3
Avatar

--
26 Jan 2010 08: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:\>
RyanGreeleyUser is Offline
New Member
New Member
Posts:3
Avatar

--
26 Jan 2010 08: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

cmille19User is Offline
New Member
New Member
Posts:65
Avatar

--
26 Jan 2010 08: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.1
right
   
footer Sponsored by Quest Software • SAPIEN Technologies • Compellent • Microsoft Windows Server 2008 footer
footer