Solved

How to increase the server timed out period

Posted on 2009-05-08
9
372 Views
Last Modified: 2012-05-06
I am running a database query in C# that extracts the data from SQL Server. I am using a data adapter and when I try to fill it using da.fill command it raises an exception saying "Timeout expired. The timeout period elapsed prior to the completion of the operation or the server is not responding. All the other queries are working fine, this is the only query which is causing the problem. when i run this query on SQL query analyzer it works fine though take long time. Is there any way I can increse the server respond time.
0
Comment
Question by:shieldguy
  • 4
  • 3
  • 2
9 Comments
 
LVL 32

Expert Comment

by:Daniel Wilson
ID: 24334966
Yes, you need to increase the CommandTimeout on your Command object.

Can you post the relevant code?
0
 
LVL 1

Author Comment

by:shieldguy
ID: 24335219
System.Data.SqlClient.SqlDataAdapter vDA;
DataSet ds = new DataSet();
            try
            {
                if (vCnSQL.State == ConnectionState.Closed) { vCnSQL.Open(); }
                vDA.SelectCommand.CommandText = Query;
                vDA.Fill(ds);
            }
            catch (Exception e)
            {
                Log("", e);
                return null;
            }
            finally
            {
                if (vCnSQL.State != ConnectionState.Closed)
                {
                    vCnSQL.Close();
                }

            }
            return ds;
0
 
LVL 1

Author Comment

by:shieldguy
ID: 24335303
I have tried increasing the commandtimeout but still it's causing the problem. Plesae have a look at the code

public void init(int connIndex)
        {
            string cnStr = GetConnectionString(connIndex);
            vCnSQL = new System.Data.SqlClient.SqlConnection(cnStr);
            vCmd = new System.Data.SqlClient.SqlCommand();
            vCmd.Connection = vCnSQL;
            vCmd.CommandTimeout = 1000000;
            vDA = new System.Data.SqlClient.SqlDataAdapter();
            vDA.SelectCommand = new System.Data.SqlClient.SqlCommand();
            vDA.SelectCommand.Connection = vCnSQL;
        }
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 24335501
Perhaps I am being dense, but where are you using the query? And don't you think that 11 days is excessive for a CommandTimeout.  Why not just set it to 0 (infinite) and then it will be more obvious as to your intent.  But first you need to set the CommandTimeout property to the correct SQLCommand object.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 1

Author Comment

by:shieldguy
ID: 24335570
set it to 0? I didn't understand that. Do we need to increase the timeout or decrease it?
0
 
LVL 32

Accepted Solution

by:
Daniel Wilson earned 500 total points
ID: 24335664
Setting it to 0 means making it infinite.

You're setting it on the wrong command object.  Try this:

public void init(int connIndex)

        {

            string cnStr = GetConnectionString(connIndex);

            vCnSQL = new System.Data.SqlClient.SqlConnection(cnStr);

            vCmd = new System.Data.SqlClient.SqlCommand();

            vCmd.Connection = vCnSQL;
 

            vDA = new System.Data.SqlClient.SqlDataAdapter();

            vDA.SelectCommand = new System.Data.SqlClient.SqlCommand();

            vDA.SelectCommand.Connection = vCnSQL;

            vDA.SelectCommand.CommandTimeout = 1000000;

        }

Open in new window

0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 24335904
>>set it to 0? I didn't understand that.<<
0 = Infinite.  The same setting used by SQL Server Query Analyzer by default.  IMHO using 1000000 is confusing and you might as well set it to 0.  It is essentially the same.

But the big question is why are you resorting to increasing the Command Timeout. Have you tried optimizing the query?
0
 
LVL 32

Expert Comment

by:Daniel Wilson
ID: 24336064
>> IMHO using 1000000 is confusing and you might as well set it to 0.

Agreed.
0
 
LVL 1

Author Closing Comment

by:shieldguy
ID: 31579381
Thanks very much for your help!! It worked perfectly.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now