Link to home
Start Free TrialLog in
Avatar of jra2002
jra2002

asked on

System.Data.SqlClient.SqlException: Timeout expired

I am getting the following exception -

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.SqlCommand.ExecuteNonQuery()

On the google I found I need to update the commandTimeOut property. How much do I need to update it and where should I update it.

My application is windows application

Thanks
Avatar of Arragorn
Arragorn
Flag of United States of America image

Hi jra2002,

You can change the the timeout period by setting the CommandTimeout property of your command object. This property is in seconds. For Example to set your timeout property to 2 mins (120 secs)
EX:

dim myCmd as SQLCommand
myCmd.CommandTimeout = 120

To determine what to set the timeout to it is important to know why the timeout is occuring. Is this a long running query etc.


John Crenshaw
john.crenshaw@ky.gov
john@jcdl.net

Consultants are people who borrow your watch to tell you what time it is, then walk off with the watch.

Avatar of jra2002
jra2002

ASKER

Dear John,
previously I had never has the problem of Timeout Today is the first tine I am getting this error

Thanks
ASKER CERTIFIED SOLUTION
Avatar of Arragorn
Arragorn
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jra2002

ASKER

Dear Arragorn
You are right. It's not the program error. Database is locked
I am experiencing the same problem, but it is not timing out from Query Analyzer, only from the app. I have cmd.CommandTimeout = 600 in the class. The server is config'd for the same. But the app times out after 25 sec. What gives?