?
Solved

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

Posted on 2010-01-03
12
Medium Priority
?
925 Views
Last Modified: 2012-05-08
when my page is loading it give me error


Timeout expired.  The timeout period elapsed prior to completion of the operation or the server is not responding.
in asp.net
0
Comment
Question by:chandresh43
12 Comments
 
LVL 17

Expert Comment

by:CSecurity
ID: 26168925
You need to tweak your code, something is wasting time in your code. See:
http://dotnethangout.blogspot.com/2007/02/timeout-expired.html
http://forums.asp.net/t/903456.aspx
0
 
LVL 15

Expert Comment

by:rajeeshmca
ID: 26168972
The various ways where you van maintain the timeout are

to change the timeout for one specific page:

<location path="somefile.aspx">
      <system.web>
            <httpRuntime executionTimeout="180"/>
      </system.web>
</location>

Additionally, you will have to set the timeout for your managed data provider (ado.net), add timeout=xx (while xx is seconds) in your connection string, and set every DbCommand.CommandTimeout property
0
 
LVL 42

Expert Comment

by:Meir Rivkin
ID: 26168973
check this post from msdn http://social.msdn.microsoft.com/Forums/en-US/vblanguage/thread/57dc992f-fcc4-4b17-8187-a9002c4bc28c/

this is happen when u deal with a large amount of data, the post suggests to increase the timeout property of the connection string (ConnectionTimeout), also u may increase the timeout of the sqlcommand which is used to query the database (CommandTimeout).
last thing, make sure u close the connection once the db routine is finish:

string connectionString ="Integrated Security=SSPI;database=northwind;server=mySQLServer;Connect Timeout=30000";

using (SqlConnection cn = new SqlConnection(connectionString))
{
string commandString = "the query..."
    using (SqlCommand cm = new SqlCommand(commandString, cn))
    {
cm .CommandTimeout = 120;

        cn.Open();
        cm.ExecuteNonQuery();
    }
}
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 5

Author Comment

by:chandresh43
ID: 26169005
i get time out error on
 dAd.Fill(dTable); this line of code

 private void BindGridViewArticels()
    {
        DataTable dTable = new DataTable();
                using (SqlConnection conn = new SqlConnection(connStr))
        {

            using (SqlCommand dCmd = new SqlCommand())
            {

                SqlParameter[] prms = new SqlParameter[4];

                prms[0] = new SqlParameter("@startRowIndex", SqlDbType.Int);

                prms[0].Value = _startIndex;

                prms[1] = new SqlParameter("@pageSize", SqlDbType.Int);

                prms[1].Value = _pageSize;

                prms[2] = new SqlParameter("@totalCount", SqlDbType.Int);

                prms[2].Direction = ParameterDirection.Output;

                prms[3] = new SqlParameter("@OrderBy", SqlDbType.VarChar);

                prms[3].Value = dropsort.SelectedItem.Value;

                dCmd.CommandText = "Engagement Ring";

                dCmd.CommandType = CommandType.StoredProcedure;

                dCmd.Parameters.AddRange(prms);

                dCmd.Connection = conn;

                using (SqlDataAdapter dAd = new SqlDataAdapter())
                {

                    // assign the select command to the Adapter object

                    dCmd.CommandTimeout = 0;
                    dAd.SelectCommand = dCmd;

                    // now open the connection

                    conn.Open();

                    dAd.Fill(dTable);

                    conn.Close(); // close the connection

                }

                _totalNumberOfRows = int.Parse(prms[2].Value.ToString());

            }

        }

        dataring.DataSource = dTable;

        dataring.DataBind();
         litPaging.Text = GetPagingDone(_thisPage-1, _totalNumberOfRows, _pageSize, "Engagement-Ring.aspx", "");
}

Open in new window

0
 
LVL 4

Expert Comment

by:apexpert
ID: 26169010
use also 'connect timeout' in your connection string.
0
 
LVL 42

Expert Comment

by:Meir Rivkin
ID: 26169051
>>dCmd.CommandTimeout = 0;

why did u set the timeout to 0?

also after this line:
using (SqlCommand dCmd = new SqlCommand())

add
dCmd.CommandTimeout =  <set timeout here>
0
 
LVL 3

Accepted Solution

by:
roeib earned 2000 total points
ID: 26169075
hey mate, i have taken your code and modified it a bit for performance, changed it to use a Custom DataAdapter that is working via a DataReader, here is the Code:

public class temp
{
    private void BindGridViewArticels()
    {
        DataTable dTable = new DataTable();
        CustomAdapter da = new CustomAdapter();
        using (SqlConnection conn = new SqlConnection(connStr))
        {
            conn.Open();
            using (SqlCommand dCmd = new SqlCommand())
            {

                SqlParameter[] prms = new SqlParameter[4];
                prms[0] = new SqlParameter("@startRowIndex", SqlDbType.Int);
                prms[0].Value = _startIndex;
                prms[1] = new SqlParameter("@pageSize", SqlDbType.Int);
                prms[1].Value = _pageSize;
                prms[2] = new SqlParameter("@totalCount", SqlDbType.Int);
                prms[2].Direction = ParameterDirection.Output;
                prms[3] = new SqlParameter("@OrderBy", SqlDbType.VarChar);
                prms[3].Value = dropsort.SelectedItem.Value;
                dCmd.CommandText = "Engagement Ring";
                dCmd.CommandType = CommandType.StoredProcedure;
                dCmd.Parameters.AddRange(prms);
                dCmd.Connection = conn;

                IDataReader dr = cmd.ExecuteReader();
                da.FillFromReader(dTable, dr); //converts a datareader into a datatable
                _totalNumberOfRows = int.Parse(prms[2].Value.ToString());

            }

        }

        dataring.DataSource = dTable;
        dataring.DataBind();
        litPaging.Text = GetPagingDone(_thisPage - 1, _totalNumberOfRows, _pageSize, "Engagement-Ring.aspx", "");
    }
}

public class CustomAdapter : System.Data.Common.DbDataAdapter
{
    public int FillFromReader(DataTable dataTable, IDataReader dataReader)
    {
        return this.Fill(dataTable, dataReader);
    }
    protected override System.Data.Common.RowUpdatedEventArgs CreateRowUpdatedEvent(DataRow a, IDbCommand b, StatementType c, System.Data.Common.DataTableMapping d)
    {
        return (System.Data.Common.RowUpdatedEventArgs)new EventArgs();
    }

    protected override System.Data.Common.RowUpdatingEventArgs CreateRowUpdatingEvent(DataRow a, IDbCommand b, StatementType c, System.Data.Common.DataTableMapping d)
    {
        return (System.Data.Common.RowUpdatingEventArgs)new EventArgs();
    }

    protected override void OnRowUpdated(System.Data.Common.RowUpdatedEventArgs value)
    {

    }
    protected override void OnRowUpdating(System.Data.Common.RowUpdatingEventArgs value)
    {

    }
}

0
 
LVL 5

Author Comment

by:chandresh43
ID: 26169155
now get error
 IDataReader dr = dCmd.ExecuteReader();
              on this line
Timeout expired.  The timeout period elapsed prior to completion of the operation or the server is not responding.
0
 
LVL 14

Expert Comment

by:Dhanasekaran Sengodan
ID: 26169344
set dCmd.CommandTimeout = 120; before this line

IDataReader dr = dCmd.ExecuteReader();
0
 
LVL 5

Author Comment

by:chandresh43
ID: 26169372
ok it work but it take so much time to load data
what is problem
0
 
LVL 42

Expert Comment

by:Meir Rivkin
ID: 26169393
@chandresh43

it depends of what the stored procedure is doing.
u might wanna check the implementation of the stored procedure.
i'd suggest sql server profiler or red gate profiler for performance analyzing.
0
 
LVL 11

Expert Comment

by:ROMA CHAUHAN
ID: 26169763
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.

Question has a verified solution.

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

OverviewThis article demonstrates a simple search form using AJAX. The purpose of the article is to demonstrate how to use the same code to render a page and javascript (JQuery) and AJAX to make subsequent calls to refine the results. The princip…
This article discusses how to implement server side field validation and display customized error messages to the client.
Integration Management Part 2
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

831 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