简体   繁体   中英

“wait operation timed out” for sql command in ASP .NET app

I have an old ASP .NET Web Forms application. Code-behind - VB .NET . It has been working for like 10 years. All was fine and worked very fast.

But yesterday I faced next problem: my SQL querys to database began to take much longer time.

I had next code in .aspx file:

<asp:SqlDataSource ID="SqlDataSource3" runat="server" 
    ConnectionString="<%$ ConnectionStrings:ConnectionString %>" 
    SelectCommand=" "SOME SELECT DB QUERY (hardcoded)" "> 
    <!-- I know, that it is bad way to configure select command. But I'm not an author -->
     <SelectParameters>
        <!-- Parameters -->
     </SelectParameters>
</asp:SqlDataSource>

This SQL query take like < 0.1 sec to be processed with every parameter (tested) on server in MS SQL management studio. Thats fine.

But my application started to take timeout error. In SQL server profiler this querys (hardcoded) was taking for > 30 sec's (timeout) (with some parameters It worked for like 14 - 20 sec's. But it is still much more longer, that was for like 2 days ago).

Important : I have solved this issue. I have maked stored procedure in my MS SQL database with this select query.

And changed .aspx code to this one:

<asp:SqlDataSource ID="SqlDataSource3" runat="server" 
    ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
    SelectCommand=" "PROCEDURENAME" " SelectCommandType="StoredProcedure">
    <SelectParameters>
        <!-- Parameters -->
    </SelectParameters>
</asp:SqlDataSource>

And that solved my issue.

Question is: Why has it solved my issue? I can't really understand this. And it's very interesting for me.

Full error code

Maybe your DB connect query might be taking more time to execute, or server is taking more time to execute DB query, You can check the server where DB is hosted. Check if there are too many application pools running for IIS.

You can also increase CommandTimeout for your connection from the config file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM