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 8860973
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T15:23:11+00:00 2026-06-14T15:23:11+00:00

I have a multithreaded C# application where I need each thread to have an

  • 0

I have a multithreaded C# application where I need each thread to have an active connection. I can’t use connection pooling unless there is a way to use static connection to update/insert multiple tables accurately in a multithreaded app without using locks.When the number of connections is around 200, it is fine. The connection does not grow beyond this. But when I need 2200+ connections, the number of connections keep growing infinitely.

Code to create connection –

 @"Data Source=Server-3-PC\SQLSERVER2012;Initial Catalog=****;Persist Security Info=True;User ID=****;Password=****;Pooling=false";

I am checking connections from SSMS using –

sp_who2
  • 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-06-14T15:23:12+00:00Added an answer on June 14, 2026 at 3:23 pm

    I found the answer. Creating connections and closing within Parallel loop is not reliable. The connections should always be created outside the loop, used inside and closed outside.

    Thank you all for looking into it.

    To better explain this, this works –

     Parallel.For(0,NumSymWatching , x =>
                    {
                        String conString = @"Data Source=TEJ-HP\SQLSERVER2012;Initial Catalog=DRMinutesData;Persist Security Info=True;User ID=sa;Password=sql;Pooling=false;";
                        SqlConnection hConnectionBars = new SqlConnection(conString);
                        hConnectionBars.Open();
                        SqlCommand hCommandBars = new SqlCommand();
                        hCommandBars.Connection = hConnectionBars;
    
                        BuildHistoricalBarData(A[x], B[x], beginFilterTimeMinutes, hCommandBars);
    
    
                        hConnectionBars.Dispose();
                        hConnectionBars = null;
    
                    });
    

    Connections are opened, used and closed just the way you want to. However, if you create connections inside the BuildHistoricalBarData method, it will keep growing.

    The reason why pooling is not used here is ‘A’ is an array of items that point to different tables. Even if it had been same table, hCommandBars would be changed (by threads running in parallel) and you could never perform accurate insert/update actions without using locks. Locks would then slow it down.

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

Sidebar

Related Questions

I have an application that I'm trying to make multithreaded. Each thread will access
I have a multithreaded application that makes heavy use of OpenSSL in C. It
I have a multithreaded application (C++) where I need to increment/change a series of
I have a multithreaded application, in which I'm trying to render with different threads.
I have a multithreaded application that has many concurrent operations going on at once.
I have a multithreaded application. However I noticed, I'm using OpenGL and this should
In a multithreaded application. I have a bunch of function that loop through a
I have a multithreaded Windows application where one of the threads has a message
I have the following problem: Multithreaded WPF application, Model View Presenter Implementation. Presenters and
More specifically, I have a multithreaded command line Java application which runs and collects

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.