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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T18:40:51+00:00 2026-05-17T18:40:51+00:00

My headache is this – my server application exceeds the maximum open database connections

  • 0

My headache is this – my server application exceeds the maximum open database connections while being under load. So, I figure I need a task queue (aka service bus) for write database access. A queue, that db write requests can be posted to it and the dedicate threads will read it and execute.

I was wondering if there are ready components out there that do just that. My requirements are:

  1. Multiple threads can write to the queue with minimum blocking.
  2. More than one thread can read from the queue to execute the posted write requests. In the most constrained case this number is 1, but it may be more, for instance 10% of the open db connection limit.

Any ideas?

Thanks.

P.S.

I have noticed this, and this, but neither seem relevant to me.

  • 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-17T18:40:52+00:00Added an answer on May 17, 2026 at 6:40 pm

    Using a BlockingCollection<T>, which implements a producer/consumer pattern. It’s thread safe, so you can access it from multiple threads simultaneously. Here’s an example of how that would be used:

    var collection = new BlockingCollection<MyClass>();
    
    // start a new background task to fill the queue
    Task.Factory.StartNew(() => {
        while(thereIsStillStuffToStoreInTheDatabase)
        {
            var item = GetNextItem();
            collection.Add(item);
        }
        collection.CompleteAdding();
    });
    
    // GetConsumingEnumerable() blocks while empty until the producer
    // has more items or it signals that adding is complete
    foreach(var item in collection.GetConsumingEnumerable())
    {
        // store item in database
    }
    

    Note that the above implementation could also be performed in reverse, with a background Task consuming from the collection and the main worker thread filling it.

    Joseph Albahari has an excellent writeup on Tasks and parallelism. You can read all about it, and specifically about BlockingCollection, here.

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

Sidebar

Related Questions

No related questions found

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.