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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T20:53:09+00:00 2026-06-02T20:53:09+00:00

I only use DataReaders two times within my application both times it looks like

  • 0

I only use DataReaders two times within my application both times it looks like this

    MySqlDataReader reader = cmd.ExecuteReader();
    while (reader.Read())
    {
       //Code
    }
    reader.Close();

Can anyone give me some pointers on how to solve this error? Or where to look? Sorry if it’s too vague but that’s what the error is telling me. It points to this point:

        MySqlCommand cmdDel = new MySqlCommand("UPDATE " + _Database + " SET balance=" + balance + ", bitaddress=" + myads + ", lostbalance=" + lostbalance + " WHERE username = '" + username + "'", connection);
        cmdDel.ExecuteNonQuery();
        cmdDel.Dispose();

My guess is that executing query commands could be not allowed inside of a while(reader.Read()) can anyone confirm on this?

  • 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-02T20:53:10+00:00Added an answer on June 2, 2026 at 8:53 pm

    This almost certainly implies that you’re sharing a connection object between multiple command objects. You should avoid doing this (unless they’re all involved in a single database transaction).

    The model you should follow generally is:

    using(var connection = new MySqlConnection("..."))
    {
       using(var cmd = new MySqlCommand("...",connection))
       {
           //Set up parameters/other settings/as required
           connection.Open();
           cmd.<Whatever ExecuteXXX method you need to use>();
           //If it was ExecuteReader, process the results now
       }
    }
    //If it was ExecuteScalar, or a fill of a DataSet or DataTable, consume the results now
    

    Unless you have specific needs which prevent it, you should prefer to wrap disposables in using statements, rather than manually calling Dispose().

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

Sidebar

Related Questions

I have a number like this: 12345678987654321 I want to only use the first
I am trying to make this landscape only iphone app. I only use this
I'm learning to develop for iPhone (programmatically, I don't like IB). I only use
I use only classes and never use IDs. Many people like to use IDs
How could I refactor this code to use only one Dir[ ] call? Dir[
I only use nXML for authoring docbook documents, and I would like to tell
I'm looking for a footer like facebook has but only use CSS to style
I have an assignment, This is my HashMap initialization.. I can only use standard
Idea taken from here - this time you can only use PHP. Is this
Is there a way to configure RubyMine 3.1 to only use two spaces to

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.