C# – Timeout Error for sql data source

asp.netcdatasourcesql

Error code:

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

Can someone provide me with code I can copy and paste so I can change the default timeout? I'm not sure where to put it into this code:

<head runat="server">
<title>Proxy Report</title>
</head>
<body>
<form id="form1" runat="server">
<div>

    <asp:Label ID="Label1" runat="server" Text="Proxy Report"></asp:Label>

</div>
<asp:GridView ID="GridView1" runat="server" DataSourceID="SqlDataSource1">
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" 
    ConnectionString="<%$ ConnectionStrings:ISALog1ConnectionString %>" 
    SelectCommand="ProxyReport" SelectCommandType="StoredProcedure">

</asp:SqlDataSource>
</form>
</body>
</html>

Best Answer

You can increase the Timeout property like this

protected void SqlDataSource1_Selecting(object sender, SqlDataSourceSelectingEventArgs e)
        {
            e.Command.CommandTimeout = 0;
        }

Setting timeout to 0 means no timeout