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

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

LVL 5
chandresh43Asked:
Who is Participating?
 
WesWilsonCommented:
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
 
infochandruCommented:
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
 
princeatapiCommented:
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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
namazikhahCommented:
0
 
ROMA CHAUHANProject LeadCommented:
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
 
WesWilsonCommented:
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
 
chandresh43Author Commented:
how i make it in stored procedure.
0
 
chandresh43Author Commented:
thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.