Solved

How to increase the server timed out period

Posted on 2009-05-08
9
375 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
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 
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

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

920 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

15 Experts available now in Live!

Get 1:1 Help Now