Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Not your normal timeout...

Not your normal timeout...

Scheduled Pinned Locked Moved C#
databasesysadminhelpquestion
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    Pualee
    wrote on last edited by
    #1

    Here is the error: System.Data.SqlClient.SqlException: Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding. I receive this after ~32 seconds of running a SqlCommand. Now, normally the default timeout is 30 seconds, but I have increased this up to 10 minutes and still the timeout happens in 30 seconds. The connection string says Timeout=600 and I do not override this anywhere in the code. In fact, I can print the timeout prior to running the query and it says 600. Am I missing something obvious here?

    R D 3 Replies Last reply
    0
    • P Pualee

      Here is the error: System.Data.SqlClient.SqlException: Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding. I receive this after ~32 seconds of running a SqlCommand. Now, normally the default timeout is 30 seconds, but I have increased this up to 10 minutes and still the timeout happens in 30 seconds. The connection string says Timeout=600 and I do not override this anywhere in the code. In fact, I can print the timeout prior to running the query and it says 600. Am I missing something obvious here?

      R Offline
      R Offline
      Ravi Sant
      wrote on last edited by
      #2

      There are two different time outs for SQLConnection and SQLCommand. Set longer timeout to the SqlCommand object (30 is default). I hope if this helps :)

      1 Reply Last reply
      0
      • P Pualee

        Here is the error: System.Data.SqlClient.SqlException: Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding. I receive this after ~32 seconds of running a SqlCommand. Now, normally the default timeout is 30 seconds, but I have increased this up to 10 minutes and still the timeout happens in 30 seconds. The connection string says Timeout=600 and I do not override this anywhere in the code. In fact, I can print the timeout prior to running the query and it says 600. Am I missing something obvious here?

        R Offline
        R Offline
        Ravi Sant
        wrote on last edited by
        #3

        Also, While declaring the command object set the timeout property 0 i.e. infinity. SqlCommand cmd = new SqlCommand(); cmd.CommandTimeout=0; Try this! :)

        P 1 Reply Last reply
        0
        • R Ravi Sant

          Also, While declaring the command object set the timeout property 0 i.e. infinity. SqlCommand cmd = new SqlCommand(); cmd.CommandTimeout=0; Try this! :)

          P Offline
          P Offline
          Pualee
          wrote on last edited by
          #4

          Very clever that you reply twice so I can give you two 5's :laugh: Answer is very much appreciated (with small modification)!

          SqlCommand cmd = new SqlCommand();
          cmd.CommandTimeout=con.ConnectionTimeout;

          Now I can still modify the timeout just from the config file's connection string.

          R 1 Reply Last reply
          0
          • P Pualee

            Here is the error: System.Data.SqlClient.SqlException: Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding. I receive this after ~32 seconds of running a SqlCommand. Now, normally the default timeout is 30 seconds, but I have increased this up to 10 minutes and still the timeout happens in 30 seconds. The connection string says Timeout=600 and I do not override this anywhere in the code. In fact, I can print the timeout prior to running the query and it says 600. Am I missing something obvious here?

            D Offline
            D Offline
            Dave Kreskowiak
            wrote on last edited by
            #5

            You're setting the timeout on the CONNECTION attempt, not the query execution timeout. You do that in the SqlCommand object you're using to execute your query.

            A guide to posting questions on CodeProject[^]
            Dave Kreskowiak

            1 Reply Last reply
            0
            • P Pualee

              Very clever that you reply twice so I can give you two 5's :laugh: Answer is very much appreciated (with small modification)!

              SqlCommand cmd = new SqlCommand();
              cmd.CommandTimeout=con.ConnectionTimeout;

              Now I can still modify the timeout just from the config file's connection string.

              R Offline
              R Offline
              Ravi Sant
              wrote on last edited by
              #6

              yes, dats better to keep config in scene! i was in hurry to head towards home, so just didnt modify and took a new message post instead :)

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups