Link to home
Start Free TrialLog in
Avatar of chandresh43
chandresh43Flag for India

asked on

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

Avatar of infochandru
infochandru
Flag of India image

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"
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"/>
Avatar of ROMA CHAUHAN
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
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.
Avatar of chandresh43

ASKER

how i make it in stored procedure.
ASKER CERTIFIED SOLUTION
Avatar of WesWilson
WesWilson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
thanks