Thursday 29 September 2011

Increasing Query timeout in .Net C#

SqlCommand command = new SqlCommand(qry, conn);
 command.CommandTimeout = 60 * 60 * 2; //2 hours

By Default CommandTimeout is 60 seconds. If the query is taking more than 60seconds, sqlcommand exits with an error.

The request filtering module is configured to deny a request that exceeds the request content length

HTTP Error 400 Bad request 
Unable to upload larger/bigger files on to Web Server (IIS)

Include the following setting in the application's Web.Config file.

<system.webServer>
        <security>
            <requestFiltering>
                <requestLimits maxAllowedContentLength="2000000000" />
            </requestFiltering>
        </security>
    </system.webServer>

This setting allows you to upload a file of size up to 2000MB .

The same can be achieved by the following command too.
%windir%\system32\inetsrv\appcmd set config "Default Web Site/<Your WebSite>" -section:requestFiltering -requestLimits.maxAllowedContentLength:2000000000