Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 19132
  • Last Modified:

Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding

I am getting the following error when i am trying to make search in my .net application (c#) based on the string entered.

Timeout expired.  The timeout period elapsed prior to completion of the operation or the server is not responding


can any one tell how to increase or set timeout property.

I ma using sqlserver2000.

thanks
0
pothireddysunil
Asked:
pothireddysunil
  • 7
  • 5
1 Solution
 
smeggheadCommented:
yes, the SqlCommand object has a property called CommandTimeout, set this before running your SQL.

0
 
pothireddysunilAuthor Commented:
I increased my commandtimeout and still its not working .  
0
 
smeggheadCommented:
in what way isn't it working ?? is it timing out ?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
smeggheadCommented:
also, are you sure that your connection is established ?? at what point is the error ?
0
 
pothireddysunilAuthor Commented:
yes  is connection is established connection.and I am using Connection object to execute my storedprocedure.Its giving  results fast in queryanalyzer.but when i am trying from my application i ma getting

Timeout expired.  The timeout period elapsed prior to completion of the operation or the server is not responding.

One more thing my application is windows application and i am using Development database server.

thanks
0
 
pothireddysunilAuthor Commented:
I am using the following GetData method to get dataset.
I am not using command object.
Where should i set the Timeout option for Command object

public DataSet GetData(string sql, string pstrName)
            {
                  SqlDataAdapter sda;
                  DataSet ds;

                  try
                  {
                        if (mCnn.State != ConnectionState.Open)
                        {
                              mCnn.Open();
                        }
                        sda = new SqlDataAdapter(sql,mCnn);
                        ds = new DataSet();
                        sda.Fill(ds, pstrName);                        
                        return ds;
                  }
                  catch(Exception anError)
                  {
                        Exception anException = new Exception(anError.Message);
                        anException.Source = THIS_CLASS + ".GetData";
                        anError = null;
                        throw anException;      
                  }
                  finally
                  {
                   mCnn.Close();
                  }
            }
0
 
smeggheadCommented:
Do something like...

      clsCommand=new SqlCommand();
      clsCommand.CommandText=InSQL;
      clsCommand.CommandTimeout=60; // 1 minute
      clsCommand.CommandType=CommandType.Text;
      clsCommand.Connection=mCnn; // Your connection object
      clsDataAdapter.SelectCommand=clsCommand;
      clsDataSet=new DataSet();
      clsDataAdapter.Fill(clsDataSet);

Smg.
0
 
pothireddysunilAuthor Commented:
Urgent Solution needed.

I am trying to change my first GetData() method with second method to assign CommandTimeout but I am getting the following error.

Could not find stored procedure 'spPOFind @pBuyerID = 'RH''.  

But with first method I am not getting any error.

I am passing sp and parameters with 'sql' string in first method.But in second method how should i modify to pass sp with parameters in same string.

public DataSet GetData(string sql, string pstrName)
            {
                  SqlDataAdapter sda;
                  DataSet ds;

                  try
                  {
                        if (mCnn.State != ConnectionState.Open)
                        {
                              mCnn.Open();
                        }
                        sda = new SqlDataAdapter(sql,mCnn);
                        ds = new DataSet();
                        sda.Fill(ds, pstrName);                        
                        return ds;
                  }
                  catch(Exception anError)
                  {
                        Exception anException = new Exception(anError.Message);
                        anException.Source = THIS_CLASS + ".GetData";
                        anError = null;
                        throw anException;      
                  }
                  finally
                  {
                        mCnn.Close();
                  }
            }


      public DataSet GetData(string sql, string pstrName)
            {
                  SqlCommand cmd;
                  SqlDataAdapter sda;
                  DataSet ds;

                  try
                  {
                        if (mCnn.State != ConnectionState.Open)
                        {
                              mCnn.Open();
                        }
                        //cmd = new SqlCommand(sql, mCnn);
                        //cmd.CommandType = CommandType.StoredProcedure;

                        cmd=new SqlCommand();
                        cmd.CommandText=sql;
                        cmd.CommandTimeout=180; // 3 minutes
                        cmd.CommandType=CommandType.StoredProcedure;
                        cmd.Connection=mCnn; // Your connection object
                        sda.SelectCommand=cmd;
                        ds=new DataSet();
                        sda.Fill(ds,pstrName);
                        return ds;
                  }

                  catch(Exception anError)
                  {
                        Exception anException = new Exception(anError.Message);
                        anException.Source = THIS_CLASS + ".GetData";
                        anError = null;
                        throw anException;      
                  }
                  finally
                  {
                        mCnn.Close();
                  }
            }
0
 
smeggheadCommented:
Change the command type to 'text' rather than 'storedprocedure'
0
 
pothireddysunilAuthor Commented:
Thanks Dude.Its working.
0
 
smeggheadCommented:
Excellent, glad I could help.

Smg.
0
 
smeggheadCommented:
You can accept my answer by clicking on 'Accept' next to one of my comments... this closes the question, and will encourage more people to help you in the future, as a lot of people don't bother helping people who don't award points...

Cheers
Smg.
0
 
tppradeep18Commented:
@smegghead: can you please tell us the reason of this behaviour. i.e. why this problem was coming when CommandType was set to StoredProcedure?
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 7
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now