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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T04:07:17+00:00 2026-05-31T04:07:17+00:00

I have two problems. One is that it is only pulling one row and

  • 0

I have two problems. One is that it is only pulling one row and sending it to ms fax when there are a few hundred to be sent. The other is that it doesn’t pull any more after that first and it throws an error. I thought I was closing out my connections. I don’t understand what the problem is. I have included the code and error.

Service1.cs

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.Timers;
using MySql.Data.MySqlClient;
using FAXCOMLib;
using FAXCOMEXLib;

namespace ProcessFaxes
{
public partial class Service1 : ServiceBase
{
    public Service1()
    {
        InitializeComponent();
    }
    public static Timer timer = new Timer();

    protected override void OnStart(string[] args)
    {

        timer.Elapsed += new ElapsedEventHandler(Tick);
        timer.Interval = 600000; // every 10 minutes
        timer.Enabled = true;
       // Console.ReadLine();
     }

    protected override void OnStop()
    {

    }

    public static void Tick(object source, ElapsedEventArgs e)
    {
        string connString = "Server=localhost;Port=3306;Database=communications;Uid=root;password=pass;";
        MySqlConnection conn = new MySqlConnection(connString);
        MySqlCommand command = conn.CreateCommand();

        MySqlConnection connupdate = new MySqlConnection(connString);
        MySqlCommand commandupdate = connupdate.CreateCommand();

        command.CommandText = "SELECT * FROM outbox WHERE `faxstat` = 'Y' AND `fax` <> '' AND `faxpro` = 'PENDING'";
        //command.CommandText = "UPDATE blah blah";
        //conn.Open();
        //conn.ExecuteNonQuery();
        //conn.Close();

        try
        {

            conn.Open();
            connupdate.Open();

        }
        catch (Exception ex)
        {
            // Console.WriteLine(Ex.Message); 
                LogException(ex.ToString());

        throw;  // or whatever you want to do with it
        }
        MySqlDataReader reader = command.ExecuteReader();

        if (reader.HasRows)
        {

            while (reader.Read())
            {
                //Console.WriteLine(reader["filepath"].ToString());
                SendFax(reader["id"].ToString(), reader["filepath"].ToString(), @"C:\FAXDOC\" + reader["filepath"].ToString(), reader["account"].ToString(), reader["fax"].ToString(), reader["fax_orig"].ToString());
                string id = reader["id"].ToString();
                commandupdate.CommandText = "UPDATE outbox SET `faxpro` = 'DONE' WHERE `id` = '" + id + "'";
                commandupdate.ExecuteNonQuery();

            }
        }

        conn.Close();
        connupdate.Close();
    }

    public static void SendFax(string DocumentId, string DocumentName, string FileName, string RecipientName, string FaxNumber, string RecipientHomePhone2)
    {
        if (FaxNumber != "")
        {
            try
            {
                FAXCOMLib.FaxServer faxServer = new FAXCOMLib.FaxServerClass();
                faxServer.Connect(Environment.MachineName);


                FAXCOMLib.FaxDoc faxDoc = (FAXCOMLib.FaxDoc)faxServer.CreateDocument(FileName);

                faxDoc.RecipientName = RecipientName;
                faxDoc.FaxNumber = FaxNumber;
                faxDoc.BillingCode = DocumentId;
                faxDoc.DisplayName = DocumentName;
                faxDoc.RecipientHomePhone = RecipientHomePhone2;

                int Response = faxDoc.Send();


                faxServer.Disconnect();

            }
            catch (Exception Ex) { 

               // Console.WriteLine(Ex.Message); 
                LogException(Ex.ToString());

        throw;  // or whatever you want to do with it
            }
        }



    }

    public static void LogException(string ErrorDescription)

    {

        // The name of our log in the event logs

        string Log = "Process Faxes";



        // Check to see fi the log for AspNetError exists on the machine

        //          If not, create it

        if ((!(EventLog.SourceExists(Log))))

        {


EventLog.CreateEventSource(Log, Log);

        }



        // Now insert your exception information into the AspNetError event log

        EventLog logEntry = new EventLog();

        logEntry.Source = Log;

        logEntry.WriteEntry(ErrorDescription, EventLogEntryType.Error);

        }


    }
}

error

Event Type: Error
Event Source:   Process Faxes
Event Category: None
Event ID:   0
Date:       3/6/2012
Time:       2:01:06 PM
User:       N/A
Computer:   FAXSERVER
Description:
MySql.Data.MySqlClient.MySqlException (0x80004005): Too many connections
   at MySql.Data.MySqlClient.MySqlStream.ReadPacket()
   at MySql.Data.MySqlClient.NativeDriver.Open()
   at MySql.Data.MySqlClient.Driver.Open()
   at MySql.Data.MySqlClient.Driver.Create(MySqlConnectionStringBuilder settings)
   at MySql.Data.MySqlClient.MySqlPool.GetPooledConnection()
   at MySql.Data.MySqlClient.MySqlPool.TryToGetDriver()
   at MySql.Data.MySqlClient.MySqlPool.GetConnection()
   at MySql.Data.MySqlClient.MySqlConnection.Open()
   at ProcessFaxes.Service1.Tick(Object source, ElapsedEventArgs e) in C:\Documents and Settings\bruser\My Documents\Visual Studio 2010\Projects\ProcessFaxes\ProcessFaxes\Service1.cs:line 56
  • 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-31T04:07:18+00:00Added an answer on May 31, 2026 at 4:07 am

    I think you should refactor a bit. I explained a little in a comment above, but here’s how I would change it (I added some comments for you too):

    public static void Tick(object source, ElapsedEventArgs e)
    {
        // Prevent another Tick from happening if this takes longer than 10 minutes
        (source as Timer).Enabled = false;
    
        // It would be better practice to put this in a settings or config file
        // so you can change it without having to recompile your application
        string connString = "Server=localhost;Port=3306;Database=communications;Uid=root;password=pass;";
    
        // I won't change them here, but since these classes implement IDisposable,
        // you should be using a using statement around them:
        // using (var conn = new MySqlConnection(connString))
        // {
        //     // use conn
        // }
        MySqlConnection conn = new MySqlConnection(connString);
        MySqlCommand command = conn.CreateCommand();
        MySqlCommand updateCommand = conn.CreateCommand();
    
        command.CommandText = "SELECT * FROM outbox WHERE `faxstat` = 'Y' AND `fax` <> '' AND `faxpro` = 'PENDING'";
    
        try
        {
            conn.Open();
    
            MySqlDataReader reader = command.ExecuteReader();
    
            if (reader.HasRows)
            {
                while (reader.Read())
                {
                    SendFax(reader["id"].ToString(), reader["filepath"].ToString(), @"C:\FAXDOC\" + reader["filepath"].ToString(), reader["account"].ToString(), reader["fax"].ToString(), reader["fax_orig"].ToString());
                    string id = reader["id"].ToString();
                    // I would use a prepared statement with either this query
                    // or a stored procedure with parameters instead of manually
                    // building this string (more good practice than worrying about
                    // SQL injection as it's an internal app
                    updateCommand.CommandText = "UPDATE outbox SET `faxpro` = 'DONE' WHERE `id` = '" + id + "'";
                    updateCommand.ExecuteNonQuery();
    
                }
            }
        }
        catch (Exception ex)
        {
            LogException(ex.ToString());
            throw;
        } 
        finally 
        {
            // If you're not going to use using-statements, you might want to explicitly
            // call dispose on your disposable objects:
            // command.Dispose();
            // updateCommand.Dispose();
            conn.Close();
            // conn.Dispose();
        }
    
        // Enable the timer again
        (source as Timer).Enabled = true;
    }
    

    As to why you’re only receiving one row when you’re expecting many, I suspect your SQL is at fault.

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

Sidebar

Related Questions

I have some localization problems in my webpage. There are basically two problems (that
I have encountered a problem in my application. I have two forms, one that
Problem: I have two spreadsheets that each serve different purposes but contain one particular
I'm having some problems trying to perform a query. I have two tables, one
I have my program that can draw rectangles. I have two problems I can't
I have a cakePHP application that is pulling data from two different databases, which
I know, I know, now I have two problems 'n all that, but regex
So i'm having this problem. I have two tables (Oracle), one is called Destination
The problem: I often have to update two or more repositories: One for the
I have two cmake-related problems: first, I can't make it to find the includes

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.