none
SqlCommand.CommandTimeout -- does this work? RRS feed

  • Question

  • I can't get reliable results when assigning a value to the .CommandTimeout when connecting to SQL 2000 and/or SQL 2005 databases.  What I'm finding is that the Timeout appears to be locked at 2 minutes (120 seconds) regardless of what the SQL server is configured at and/or any value I assign to .CommandTimeout.

     

    Can someone clarify the purpose and/or clarify how this can be used -- perhaps I'm not setting something up correctly, but I'm stumped.

     

    Thanks, Rob.

     

    Monday, April 14, 2008 6:08 PM

All replies

  • Command Timeout is only used for the execution of a command, there is also a Connection Timeout related to connecting, and a General Timeout.  What are you trying to use the command timeout to do?

    Thanks,

    John
    Thursday, April 17, 2008 5:15 PM
  •  

    In what context are you trying to use the connection? If via an ASP.NET app, you'll probably want to ensure that your executionTimeout is set properly. By default it's 2 minutes.

     

    Open web.config for the app and search for httpRuntime. Add an executionTimeout to the tag and give it an appropriate value. Something like the following:

     

    <httpRuntime maxRequestLength=”51200” executionTimeout=”9000” />

     

    Hope this helps.

    Thursday, May 15, 2008 8:49 PM
  • Ah, I would question why you need to execute a query that takes that long? Let's assume it makes sense, but if it does, I would not expect your web site to support many users--probably not more than a handful.

    Thursday, May 15, 2008 10:09 PM
    Moderator
  •  William Vaughn wrote:

    Ah, I would question why you need to execute a query that takes that long? Let's assume it makes sense, but if it does, I would not expect your web site to support many users--probably not more than a handful.

     

    Yep, not every ASP.NET application is a website that needs to support multiple concurrent users with simple OLTP-based queries. You do raise a good point though. The example I provided above is actually from a SharePoint and SQL Server Reporting Services integrated application, and the setting is in place to match the "native" SSRS timeout of 9000 (2.5 hours). Most "web sites" would never need a query to run this long... "web applications" on the other hand .......

     

     

    Thursday, May 15, 2008 11:03 PM