Tuesday, 9 February 2021

System.Web.HttpException: Request timed out

 Server Error in '/' Application. Request timed out. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Web.HttpException: Request timed out.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.


Stack Trace:

[HttpException (0x80004005): Request timed out.]

To solve the timeout issue we can specify the request timeout (in seconds) in the web.config, like this:

<httpRuntime executionTimeout="300" />

For context, here's a complete web.config with just this setting:

<configuration>
    <system.web>
        <httpRuntime executionTimeout="300" />
    </system.web>
</configuration> 

Also you can Open IIS -> click on the your siteName -> configuration Editor on the Section, scroll to system.web/httpRuntime. Increase the executionTimeout to the time you think it will take to execute your process.

Friday, 21 September 2018

SQL Server - SET XACT_ABORT

SET XACT_ABORT                                                                                                                                                                     
Usually we use TRY… CATCH block of error handling where in CATCH block transaction is rolled back. But sometimes we simply use BEGIN.. COMMIT transaction without any TRY..CATCH block. In this scenario entire batch is not rolled back.

           BEGIN TRANACTION
                   INSERT 1
                   INSERT 2                  --This statement failed
                   INSERT 3
           COMMIT TRANSACTION

In above  case INSERT 1 and INSERT 3 still executes successfully.
SET XACT_ABORT
  • It is ideal for "all or nothing" kind of transactions.
  • It takes the whole batch as one transaction. If any of the statement in batch fails, whole batch is rolled back.

          SET XACT_ABORT ON
           BEGIN TRANACTION
                   INSERT 1
                   INSERT 2                  --This statement failed
                   INSERT 3
           COMMIT TRANSACTION

  • In this case INSERT 1 and INSERT 3 are also rolled back.
Advantage
  • TRY .. CATCH does not catch the schema related errors. It will return an error without hitting CATCH block where you have rolled back opened transaction. So You will end up with an opened transaction.
  • XCAT_ABORT rolls back transaction as soon as error occurs. So there will be no open transaction. Open transactions are major cause of performance degradation.
Disadvantage of using with TRY .. CATCH block (For non-schema related errors)
  • As CATCH block will not be executed, If you are handling / raising error in CATCH block. It will not be possible.

Friday, 27 July 2018

SQL Server Date Format conversion

SELECT convert(varchar, getdate(), 100) -- mon dd yyyy hh:mmAM

SELECT convert(varchar, getdate(), 101) -- mm/dd/yyyy – 10/02/2008                  

SELECT convert(varchar, getdate(), 102) -- yyyy.mm.dd – 2008.10.02           

SELECT convert(varchar, getdate(), 103) -- dd/mm/yyyy

SELECT convert(varchar, getdate(), 104) -- dd.mm.yyyy

SELECT convert(varchar, getdate(), 105) -- dd-mm-yyyy

SELECT convert(varchar, getdate(), 106) -- dd mon yyyy

SELECT convert(varchar, getdate(), 107) -- mon dd, yyyy

SELECT convert(varchar, getdate(), 108) -- hh:mm:ss

SELECT convert(varchar, getdate(), 109) -- mon dd yyyy hh:mm:ss:mmmAM (or PM)

SELECT convert(varchar, getdate(), 110) -- mm-dd-yyyy

SELECT convert(varchar, getdate(), 111) -- yyyy/mm/dd

SELECT convert(varchar, getdate(), 112) -- yyyymmdd

SELECT convert(varchar, getdate(), 113) -- dd mon yyyy hh:mm:ss:mmm

SELECT convert(varchar, getdate(), 114) -- hh:mm:ss:mmm(24h)

SELECT convert(varchar, getdate(), 120) -- yyyy-mm-dd hh:mm:ss(24h)

SELECT convert(varchar, getdate(), 121) -- yyyy-mm-dd hh:mm:ss.mmm

SELECT convert(varchar, getdate(), 126) -- yyyy-mm-ddThh:mm:ss.mmm