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

  • Home
  • SEARCH
  • 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 267443
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T23:33:07+00:00 2026-05-11T23:33:07+00:00

We have a winforms application calling a stored procedure every few seconds. The stored

  • 0

We have a winforms application calling a stored procedure every few seconds. The stored procedure always returns a resultset with 0 or more rows and the client fills a dataset. Once every few days or so we are finding that the dataset has no tables in it, and we can’t figure out why. The process of firing the stored procedure does happen in a thread, but the database connection and execution of the stored procedure all happens within that same thread, so there isn’t any data being passed between threads here.

Has anyone experienced behavior like this before?

Here is the relevant code, it’s part of a larger application, so I’ve tried to include only the relevant bits.

//Used by the main application to poll a database in a thread
public class Poller
{
    private Thread thProcess_m;
    private readonly Action<Exception> actOnError_m;
    private readonly RuntimeData pRuntime_m;
    private readonly DataAccessLayer dalDB_m;

    private bool bRetry_m;

    public Poller(RuntimeData pData, Action<Exception> actOnError)
    {
        this.thProcess_m = new Thread(Main);
        this.thProcess_m.Name = "Main ScriptOr Polling Thread";

        this.actOnError_m = actOnError;
        this.dalDB_m = new DataAccessLayer(ConfigurationState.ConnectionStrings.DB);
    }

    public void Start()
    {
        this.thProcess_m.Start();
    }

    protected override void Main()
    {
        while (this.pRuntime_m.Running)
        {
            try
            {
                int iQueued;
                Task pTask = this.dalDB_m.GetNextTask(out iQueued);
            }
            catch (Exception ex)
            {
                this.actOnError_m(ex);
            }
        }
    }
}

public class RuntimeData
{
    private bool bRunning_m;
    public bool Running
    {
        get
        {
            return bRunning_m;
        }
        set
        {
            bRunning_m = value;
        }
    }
}

public class DataAcessLayer
{
    public Task GetNextTask(out int iQueued)
    {
        iQueued = 0;
        Task tskNext = null;

        SqlCommand cmdNextTask = new SqlCommand();
        cmdNextTask.CommandType = System.Data.CommandType.StoredProcedure;
        cmdNextTask.CommandText = "pGetNextTask";        

        cmdNextTask.Connection = new System.Data.SqlClient.SqlConnection();
        cmdNextTask.Connection.ConnectionString = "my connection string";
        cmdNextTask.Connection.Open();

        DataSet dsNextTask = new DataSet();

        try
        {
            System.Data.SqlClient.SqlDataAdapter sqlNextTask = new System.Data.SqlClient.SqlDataAdapter(cmdNextTask);            
            sqlNextTask.Fill(dsNextTask);
        }
        finally
        {
            cmdNextTask.Connection.Close();
        }

        tskNext = LoadTask(dsNextTask);
        if (dsTask.Tables[0].Rows.Count > 0)
        {
            iQueued = (int)dsTask.Tables[0].Rows[0]["Queued"];
        }
        return tskNext;
    }

    protected Task LoadTask(DataSet dsTask)
    {
        Task tskNext = null;

        if (dsTask == null)
        {
            throw new ArgumentNullException("LoadTask DataSet is null.");
        }

        if (dsTask.Tables == null)
        {
            throw new NullReferenceException("LoadTask DataSet.Tables is null.");
        }

        //Here's where the exception is being thrown
        if (dsTask.Tables.Count == 0)
        {
            throw new ArgumentOutOfRangeException("LoadTask DataSet.Tables.Count == 0.");
        }

        if (dsTask.Tables[0].Rows.Count > 0)
        {
            DataRow drTask = dsTask.Tables[0].Rows[0];

            tskNext = new InteriorHealth.ScriptOr.ScriptTask((int)(drTask["id"]));
            tskNext.Name = pRow["Name"].ToString();
        }
        return pTask;
    }
}
  • 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-11T23:33:08+00:00Added an answer on May 11, 2026 at 11:33 pm

    I moved the instantiation of DataAccessLayer out of the constructor and into the Main() method. I haven’t seen the problem since, so I am thinking it solved the problem. I think the issue was that the constructor happens in the main application thread, so the DataAccessLayer instance was outside of the thread. Moving the instantiation into the Main() method allows the thread to own the object.

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

Sidebar

Ask A Question

Stats

  • Questions 156k
  • Answers 156k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer DECLARE @test XML SET @test = '<Products><ProductId>1</ProductId><ProductId>2</ProductId></Products>' DECLARE @Temp TABLE(ProductId… May 12, 2026 at 10:56 am
  • Editorial Team
    Editorial Team added an answer It appears that the value of OPEN_EXISTING is 3. MSDN… May 12, 2026 at 10:56 am
  • Editorial Team
    Editorial Team added an answer Yeah, using regexes was my gut reaction too, but with… May 12, 2026 at 10:56 am

Related Questions

Looking for some direction here as I'm running into some migration problems. We have
Problem: We have a web app that calls some web services asynchronously (from the
I am a newbie to WPF and have a couple of questions about WPF
We have a WinForms application written in C# that uses the AxAcroPDFLib.AxAcroPDF component to

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.