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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:46:31+00:00 2026-05-25T20:46:31+00:00

I listen a data stream and store data as insert statements in a ConcurrentQueue

  • 0

I listen a data stream and store data as insert statements in a ConcurrentQueue and insert the data with bulk insertion using a System.Threading.Timer with an interval of 1000 . The whole scenario runs on a static class.
Here is the code:

static void timer_Elapsed(object sender, ElapsedEventArgs e)
{
    if (queryQueue.IsEmpty)
        return;
    string text = "";
//bulkBuilder is StringBuilder.
//queryQueue is ConcurrentQueue
    bulkBuilder.AppendLine("PRAGMA synchronous = 0;PRAGMA count_changes = FALSE;PRAGMA journal_mode=OFF;Begin;");
    while (queryQueue.TryDequeue(out text))
    {
        bulkBuilder.Append(text);
        bulkBuilder.AppendLine(";");
    }
    bulkBuilder.AppendLine("Commit;");

    try
    {
        sqlCommand.CommandText = bulkBuilder.ToString();
        sqlCommand.ExecuteNonQuery();
    }
    catch (System.Exception ex)
    {
        Console.WriteLine("Error while inserting Data : " + ex.Message);
    }
    finally
    {
        bulkBuilder.Clear();
    }

}

Funny thing is, sqlCommand is used just for insertion, just to ExecuteNonQuery() in this timer. And time to time a get an error saying “Cannot set commandtext while a datareader is active.” This is nonsense since this code has nothing to do with the inner SQLiteDataReader in the sqlCommand.

How can I get rid of this error?

  • 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-25T20:46:31+00:00Added an answer on May 25, 2026 at 8:46 pm

    I would create a new SqlCommand (or whatever the type of sqlCommand is) for each SQL statement. Let the connection pool handle making it all efficient – each time you need to do something with the database:

    • Create and open the connection
    • Create the command
    • Execute the command
    • Dispose of the command and connection (with a using statement)

    That way you can’t end up with the local state of one command affecting another command, other than due to running out of connection pool space etc.

    Developers often try to optimize by using one connection (and potentially command) over and over, but this is a false economy and leads to problems like the one you’ve shown.

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

Sidebar

Related Questions

How can I listen to data pushed by the server using http connection ?
Hi everyone I am trying to stream multimedia data using chunked encoding. So I
I am using the listen plugin for jQuery for binding events to dynamically created
I know that with Node.js you can stream data. But why doesn't this code
I'm writing a program in C++ to listen to a stream of tcp messages
I'm try to send and get data using sockets between Adobe flash client and
I'm using some code related to RTSP, RTP to listen to various RTSP Streams
I got success in sending/receiving data using TCP Sockets over LAN but I want
I have a file with data listed as follows: 0, 2, 10 10, 8,
I listen to the podcast java posse, on this there is often discussion about

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.