0

i have developed a web application asp.net C#.

on a button click i am connecting to the database which takes long time to execute. initially it use to timeout. now i increased the commondtimeout property ,

cmd.CommandTimeout = 500;

basically it processing of paygroups. time required depends on num of employess in that paygroup.

so my question is if 1 of paygroup requires less time to execute say 2 or 3 mins, will the connection sill be open for specified time in commandtimeout property?

if yes . can we estimate the processing time and set the time accordingly .

4
  • but why do you want to set lesser time? set the upper bound only Commented Apr 4, 2012 at 5:59
  • 1
    FYI, the language is named "C#", not "csharp". Commented Apr 4, 2012 at 6:03
  • CommandTimeout is an upper threshold - if the command completes in less time, any synchronous code will continue as soon as the command completes. Commented Apr 4, 2012 at 6:10
  • Please check new answer. Commented Apr 11, 2012 at 11:10

2 Answers 2

2

why dont you try out something like this

using (SqlConnection cn = new SqlConnection(connectionString)) 
{
  //your codee to perform database operation
}

this will close your connection once your work get completed.

Sign up to request clarification or add additional context in comments.

1 Comment

@kumarchaudhari - you can set the value there no issue in it but it remain for this scop only..
0
  1. In Order to let the Query execute completely, Set the CommandTimeOut = 0.
  2. Why It is taking so much time? Your transaction should be quick enough to let other query execute in time.
  3. SQL Profiler can help you optimize your database queries. I assume you are using SQL Server

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.