.NET/SQL TimeOut Problem

I am calling a T-SQL stored procedure from VB.NET. It works fine when it is asked to return results for 30 students, but for larger numbers of students, it times out in 30 seconds. How can I best extend this TimeOut time?
Charles L BelnaOwnerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Fernando SotoRetiredCommented:
Hi belna;

You can change the command timeout as shown below.

using (SqlConnection connection = new SqlConnection(connectionString)) {
    connection.Open();
    SqlCommand command = new SqlCommand(queryString, connection);
    // Setting command timeout to 1 minute / 60 seconds
    // The parameter is set in seconds
    command.CommandTimeout = 60;

    // Other code here
}

Open in new window

0
Ramkisan JagtapLead DeveloperCommented:
You can set it in connection string in your web.config as below :
<add name="ConnectionString" connectionString="Data Source=;Initial Catalog=;Persist Security Info=True;User ID=sa;Password=sa@123;Connect Timeout=200" providerName="System.Data.SqlClient"/>
0
Fernando SotoRetiredCommented:
Hi belna;

The two solutions posted so far are addressing two different problems. my solution is adjusting the CommandTimeout. In order to get this error your command had to have made it to the server without issue and is processing the command but the command has taken more then 30 seconds to process, which is the default for this command, and so it fails. The solution posted by Ramkisan Jagtap will occur if when a command was issued to the server but was unable to connect to the server with in 15 seconds which is the default unless you have adjusted it to some other value.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Thunder724Commented:
Maybe the issue is not the timeout; but the stored procedure.  30 seconds is a long time and I'd wonder if the SP is optimized correctly.  Just a thought.
0
Charles L BelnaOwnerAuthor Commented:
Thanks Fernando!
0
Fernando SotoRetiredCommented:
Not a problem Charles, glad to help.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.