views:

244

answers:

3

Hi folks,

I get the following error upon running a query.

*

System.Data.SqlClient.SqlException: Timeout expired.
The timeout period elapsed prior to completion of the operation or the server is not responding. at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)

*

Is this a connection timeout or command timeout?

TIA

+1  A: 

You will need to post more code as to how you connection and what you are trying to execute. A command timeout propogates to a sqlexception timeout error so it could be.

What is the commmand or query you are trying to run? Once posted we may help optimize it. You can also try to set a timeout period for both the connection and the command object. Increase it and see if it helps.

JonH
@JonH - the query works if condition is to match an ID of int datatype but times out when using a date range. So, the connection works but the error doesn't give a clue as to what timedout.
SoftwareGeek
A: 

How long does the query take when run from SSMS?

If fast, then you problem could be a deadlock.

Are you using any transactions? Are you sharing the database with other applications/users?

More info will be very useful.

callisto
the query runs fine in SSMS when using a variable of datetime type but if i directly substitute the value of the date as varchar then it takes for ever to complete.For ex: 1) Where updateddate > @date (works fine).2) Where updateddate > '01/05/2010' (takes forever).What's the need to convert to datetime?
SoftwareGeek
@BhehaFry Have you tried doing a CAST in the queury to cast the string as datetime? ie Select Col1, Col2, col3 from tbl where myDate = CAST(@datestring as datetime) Also if you are using SELECT *, dont.
callisto
+1  A: 

Looks like a command timeout. If you have a connection timeout, you will see from the stack trace that it's thrown from a call to SqlConnection.Open. Any other timeout will be a command timeout.

Joe