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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T18:21:55+00:00 2026-06-06T18:21:55+00:00

This one is driving me insane, and i can’t figure out why it’s throwing

  • 0

This one is driving me insane, and i can’t figure out why it’s throwing this error.

Here is my Program.cs

MySQLProcessor.Connection = MySQLProcessor.OpenCon();
        MySQLProcessor.ThreadingConnection = MySQLProcessor.OpenCon();
        DataTable All_Websites_DataTable =  MySQLProcessor.DTTable("select BaseURL,subURL from CouponExtractor.tblUrls where GroceryStoreBit = b'0'",MySQLProcessor.Connection);
        MySQLProcessor.Connection.Dispose();
Semaphore _pool = new Semaphore(1, 50);
        Parallel.ForEach(All_Websites_DataTable.AsEnumerable(), website_DataRow =>
        {
            _pool.WaitOne();
            //additional_subURL is used to crawl threw additional URLs until unqiue value is hit
            int additional_subURL = 0;
            Catch_Old_Values = false;

            string baseURL = All_Websites_DataTable.ItemArray[0].ToString();
            string subURL = All_Websites_DataTable.ItemArray[1].ToString();
            string complete_url = string.Empty;

            //need a bool to check homepage without crawling subpages
            bool check_homepage = true;
            complete_url = baseURL + "/" + subURL.Replace("@", additional_subURL.ToString());
            string mysqlquery_siteprocesslog = "insert into tbllogs(message,timestampcolumn) Values('Processing: " + complete_url + "',Now())";
            MySQLProcessor.MySQLInsertUpdate(mysqlquery_siteprocesslog,MySQLProcessor.ThreadingConnection);

            //as long as catch_old_values is false, the app will continue crawling the website until it hits an old value
            while (Catch_Old_Values == false)
            {
                additional_subURL++;


                if (additional_subURL >= 7)
                {
                    Catch_Old_Values = true;
                    break;
                }
                else if (check_homepage == true)
                {
                    //set check_homepage to false because we will crawl the homepage and dont want to do it again.
                    check_homepage = false;
                    SiteProcessing.ProcessSite(baseURL, baseURL);


                }
                else
                {
                    complete_url = baseURL + "/" + subURL.Replace("@", additional_subURL.ToString());
                    SiteProcessing.ProcessSite(complete_url, baseURL);
                }

            }
            _pool.Release();
        });

For length of post sake here is the only section of SiteProcessing that accesses MysqlProcessor

 if (hotitem == true)
                    {
                        string mysqlquery_InserthotResults = "insert into couponextractor." + targetTable + " (BaseURL,Description,realURL,TimeStampcolumn,uniqueKey,hotkey) Values ('" + baseURL + "','" + description.Replace("'", "") + "','" + realURL + "',Now(),'" + uniqueKey.Replace("'", "") + "','" + hotitemkey + "')";
                        MySQLProcessor.MySQLInsertUpdate(mysqlquery_InserthotResults, MySQLProcessor.ThreadingConnection);
                    }
                    else
                    {
                        string mysqlquery_InsertResults = "insert into couponextractor." + targetTable + " (BaseURL,Description,realURL,TimeStampcolumn,uniqueKey) Values ('" + baseURL + "','" + description.Replace("'", "") + "','" + realURL + "',Now(),'" + uniqueKey.Replace("'", "") + "')";
                        MySQLProcessor.MySQLInsertUpdate(mysqlquery_InsertResults, MySQLProcessor.ThreadingConnection);
                    }

And here is Mysqlprocessor

public static MySqlConnection Connection { get; set; }
    public static MySqlConnection ThreadingConnection { get; set; }
    public static MySqlConnection OpenCon()
    {
        MySqlConnection masterOpenCON = new MySqlConnection("removed for privacy");
        masterOpenCON.Open();
        return masterOpenCON;
    }

    public static DataTable DTTable(string mysqlQuery, MySqlConnection MysqlCon)
    {
        DataTable DTTableTable = new DataTable();
        using (MysqlCon)
        {
            using (MySqlDataAdapter DataDTTables = new MySqlDataAdapter(mysqlQuery, MysqlCon))
            {
                DataDTTables.SelectCommand.CommandTimeout = 2500;
                using (DataTable DataDTTablesDT = new DataTable())
                {
                    DataDTTables.Fill(DataDTTablesDT);
                    DTTableTable = DataDTTablesDT;
                    DataDTTablesDT.Dispose();
                }

            }
        }

        return DTTableTable;
    }

    public static void MySQLInsertUpdate(string MySQLCommand, MySqlConnection MysqlCon)
    {
        try
        {
            using (MysqlCon)
            {
                MySqlCommand MySQLCommandFunc = new MySqlCommand(MySQLCommand, MysqlCon);
                MySQLCommandFunc.CommandTimeout = 2500;
                MySQLCommandFunc.ExecuteNonQuery();
            }
        }
        catch (Exception ex)
        {
            if (ex.Message.ToString().Contains("Duplicate entry"))
            {
                //SiteController.Catch_Old_Values = true;
            }
            else if (ex.Message.ToString().Contains("Data too long for column"))
            {


            }
            else
            {
                EventLog.WriteEntry("CouponCrawler", ex.Message.ToString(), EventLogEntryType.Error);
            }
        }
    }

I’m so confused, I clearly Dispose of MySQLProcessor.Connection in Program.CS before i even enter the Threading. And then I never call a datareader in the rest of the app. Any help is welcomed i’m going insane..

The exception is being thrown here:

using (MysqlCon)
            {
                MySqlCommand MySQLCommandFunc = new MySqlCommand(MySQLCommand, MysqlCon);
                MySQLCommandFunc.CommandTimeout = 2500;
                MySQLCommandFunc.ExecuteNonQuery();
            }
  • 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-06T18:21:56+00:00Added an answer on June 6, 2026 at 6:21 pm

    A ‘using’ statement is going to dispose the object once execution leaves the body of the using statement. In your foreach loop you’re going to dispose your connection the first time you call MySQLInsertUpdate.

    Also (and the reason for your exception), is that by doing a parallel foreach you will execute two queries at the same time on the same connection.

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

Sidebar

Related Questions

I'm tearing my hair out over this one - its driving me mad because
This one is driving me absolutely insane, especially because I have a suspicion that
This one is driving me crazy. Here's the XAML: <UserControl x:Class=SilverlightApplication1.Page xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml> <Grid
Hoping someone here has conquered this one 'cuz it's driving me crazy. My app
This one's got me stumped and it's driving me nuts. I have a SiteFinity
No luck at MSDN with this one, which is driving me nuts. I us
I have this problem that is driving me insane. I have a project to
I am facing an issue that is driving me insane. I have one and
This one is driving me crazy. AssemblyDefinition asm1 = AssemblyDefinition.ReadAssembly(example); AssemblyDefinition asm2 = AssemblyDefinition.ReadAssembly(example2);
I've been driving myself crazy over the past few days over this one. We've

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.