Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6022271
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T03:50:04+00:00 2026-05-23T03:50:04+00:00

My job seems to be hanging when opening an SQL connection. An example that

  • 0

My job seems to be hanging when opening an SQL connection. An example that reproduces the issue is as follows:

$myJob = start-job -ScriptBlock {
     $connection_string = [string]::Format("Data Source={0};Initial Catalog={1};User ID={2}; Password={3};Connection Timeout=5", "my_sql_server", "my_database", "my_user", "my_password");
     $connection = New-Object System.Data.SqlClient.SqlConnection -ArgumentList $connection_string;
     Write-Output "Opening Connection...";
     $connection.Open();
     Write-Output "Connection Opened!";
}

When I look at $myJob, it is always in the state of Running, with the output “Opening Connection…”. If I run the same code outside of a job block, it runs fine.

How do I correctly open SqlConnection inside of a job?

EDIT:

Here are the properties of $myJob:

PS C:\Documents and Settings\agprax>>> $myJob

Id              Name            State      HasMoreData     Location             Command                  
--              ----            -----      -----------     --------             -------                  
3               Administrator   Running    True            localhost             ...     

Here is the job’s output:

PS C:\Documents and Settings\agprax>>> Receive-Job $myJob
Opening Connection...
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T03:50:05+00:00Added an answer on May 23, 2026 at 3:50 am

    What OS are you running this job from? It is worth noting there is a bug submitted on Connect that appears to be related to the issue you are having.

    https://connect.microsoft.com/PowerShell/feedback/details/499499/adding-a-snapin-add-pssnapin-from-within-a-job-start-job-causes-job-to-hang-indefinitely

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

A job came in to me that's built with CodeCharge - had a look
I have a cron job on an Ubuntu Hardy VPS that only half works
In a previous job we had a classic ASP application that no one wanted
It seems that in most cases the C# compiler could call Dispose() automatically. Like
I've just started a new job and noticed that the analysts computers are connected
I started a new job in a company that loves using the word, enterprise.
I'm using jQuery. serialize seems not fit for this job.
I want to schedule job that would run immediately once the server is up,
It seems to me that both signal and socket can be used for this
I'm attempting to submit a job using the XGrid API. I've opened a connection,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.