Solved

How to increase the server timed out period

Posted on 2009-05-08
9
378 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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
 
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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

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 …
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.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

810 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