?
Solved

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

Posted on 2010-01-04
8
Medium Priority
?
433 Views
Last Modified: 2012-05-08
i get this error

void semilarproduct()
    {
        string strQuery = "SELECT TOP 3 * FROM shivproductwithsaleprice  where subcategory='" + Lblsubcategory.Text + "' ORDER BY NEWID()";
        SqlDataAdapter da = new SqlDataAdapter(strQuery, connStr);
        
       
            DataTable dt = new DataTable();
    
        
        da.Fill(dt);


        Datamatchproduct.DataSource = dt;
        Datamatchproduct.DataBind();
    }

Open in new window

0
Comment
Question by:chandresh43
8 Comments
 
LVL 3

Expert Comment

by:infochandru
ID: 26169455
check your connection string
mainly the server IP
If the IP is unreachable then this kind of errors occurs

for example,
connection string looks like "Data Source=10.100.1.1;Initial Catalog=TEST;Persist Security Info=True;User ID=demo;Password=demo"
0
 
LVL 11

Expert Comment

by:princeatapi
ID: 26169457
Are You Sure Your SQL  Server Manager  Returns the expected results in time ? Use Either Sql Query Analyzer if you found the delay is too high then check for Connectivity Issues in Sql Server , else if its okay then

Try adding a Connect Timeout in the web.config

<add key="DBConnection" value="server=LocalHost;uid=sa;pwd=;database=DataBaseName;Connect Timeout=200; pooling='true'; Max Pool Size=200"/>
0
 
LVL 3

Expert Comment

by:namazikhah
ID: 26169639
0
Independent Software Vendors: 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!

 
LVL 11

Expert Comment

by:ROMA CHAUHAN
ID: 26169761
Best link to solve your problem. Various solutions of your problem.
http://tipsstation.com/article/Timeout-expired-server-is-not-responding-Asp-Dot-Net.aspx
0
 
LVL 8

Expert Comment

by:WesWilson
ID: 26171559
Setting your Connection Timeout higher as princeatapi suggests makes sense, as does setting the Command Timeout higher, as the article from namazikhah suggests. These, and common network issues referenced by the article from roma2208 are worth checking into.

My additional suggestions are:

1. You should get higher performance from this query if you make it into a stored procedure.

2. Also you should probably consider an index on subcategory.

3. Finally, why are you ordering by NewID()? I don't know how much that is impacting performance, but I'm curious about what you are trying to accomplish with it.
0
 
LVL 5

Author Comment

by:chandresh43
ID: 26177219
how i make it in stored procedure.
0
 
LVL 8

Accepted Solution

by:
WesWilson earned 2000 total points
ID: 26180450
Run this in SQL Server Management Studio.

CREATE PROCEDURE GetProductBySubCategory
    (
    @Subcategory int
    )
AS
    SELECT TOP 3 * FROM shivproductwithsaleprice  
    WHERE subcategory = @Subcategory
    ORDER BY NewID();

The you would adjust your calling code to something like this:

void semilarproduct()
    {
        SqlConnection connection = new SqlConnection(connStr);
        SqlCommand cmd = new SqlCommand("GetProductBySubCategory", connection);
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.Parameters.AddWithValue("@Subcategory", Lblsubcategory.Text);
      
        DataTable dt = new DataTable();
        
        dt.Load(cmd.ExecuteReader());

        Datamatchproduct.DataSource = dt;
        Datamatchproduct.DataBind();
    }

Open in new window

0
 
LVL 5

Author Closing Comment

by:chandresh43
ID: 31672291
thanks
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

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.
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses

862 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