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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T21:45:15+00:00 2026-05-19T21:45:15+00:00

i am trying to implement a timeout on my database querys…so if an operation

  • 0

i am trying to implement a timeout on my database querys…so if an operation runs for too long i need to cancel the query and return a timeout message to an asp.net page….

heres the code i was using for the timeout portion….problem is i am sometimes getting partial result sets from the query…

RunSearch search = new RunSearch(GetSearchResults);
Thread searchThread = new Thread(delegate() {
dsRes =   search.Invoke(ProcessingID, 
objSqlConnection,SearchStartTime); });

searchThread.Start();
// searchThread.Join(ResultPollingPeriod * 1000);

if (!searchThread.Join(ResultPollingPeriod * 1000))
{
    searchThread.Abort();
    dsRes = null;
    return ReturnTimeoutMessage();
}
else
{
    return dsRes;
}

any help is much appreciated…

  • 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-19T21:45:15+00:00Added an answer on May 19, 2026 at 9:45 pm

    There are a couple of ways to handle this depending on your goals but you shouldn’t have to write your own implementation of this. You could set the timeout on the database itself so you don’t have to deal with this in code. If you want it to be client side defined though here are two types of timeouts to consider: Connection timeouts and command timeouts.

    A connection timeout is when it can’t connect to the server. This is set in the connection string settings by adding a Connect Timeout=30. If it doesn’t establish a connection within 30 seconds it will timeout.

    If it does establish a connection, then you need a command timeout on the SqlCommand object:

    using (SqlCommand myCommand = new SqlCommand())
    {
        myCommand.CommandTimeout = 30;
        //the rest of your command setup here
    }
    

    It’s my understanding that the CommandTimeout runs concurrently with the connection timeout – so if it takes 29 seconds to connect the command has to execute and return within 1 second.

    These timeouts will throw exceptions which you can then catch and do as you’d like (return a timeout message to an ASP.NET page or somesuch).

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

Sidebar

Related Questions

I'm trying to implement a custom TrackingParticipant for WF 4. I can write the
I am trying to implement some custom security code into SSRS 2008 (not R2)
Trying to implement a MSMQ-backed WCF PubSub. I understand that net.msmq is one-way; however
I'm trying to implement the code from showing dialog while loading layout by setContentView
I'm trying to implement a view tracking web service on my website. I'm using
I am trying to implement functionality wherein an attribute, once set, cannot be changed
I've been trying to implement a 3 column fluid layout by following http://www.alistapart.com/articles/holygrail/ (left
I’m currently trying to implement webfonts on the site I build, I want to
I have read all of the docs and there doesnt seem to be too
I comiled nginx like to enable push module(http://pushmodule.slact.net/) to implements nginx comet server. When

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.