Tuesday, May 16, 2017

Maximum request length exceeded

ASP.NET by default has a limit of 4 MB of file upload. In order to bump up this limit, web.config needs to be updated. Below is example to allow 1 GB of file upload (1 GB = 1048576 KB = 1073741824 Bytes).
<configuration>
 <system.web>
  <httpRuntime maxRequestLength="1048576" />
 </system.web>
</configuration>
For IIS 7 or later, the following is also needed. Max size value in KB and Bytes must match in both places.
<system.webServer>
 <security>
  <requestFiltering>
   <requestLimits maxAllowedContentLength="1073741824" />
  </requestFiltering>
 </security>
</system.webServer>
In order to specify execution timeout, add executionTimeout value in seconds as follows.
<configuration>
 <system.web>
  <httpRuntime maxRequestLength="1048576" executionTimeout="3600" />
 </system.web>
</configuration>

Thursday, May 4, 2017

Remove time info from getdate()

In SQL Server, a quick efficient way to remove time info from getdate() is

Select [Today] = DateAdd(dd, DateDiff(dd, 0, getdate()), 0)


The result would be something like '2017-05-04 00:00:00.000', which is handy when comparing against date-only column values.

Wednesday, May 3, 2017

SQL Server Transaction - Basic Syntax Example

A quick refresher on proper SQL Server transaction syntax example:

BEGIN TRANSACTION;
BEGIN TRY

    UPDATE dbo.Users set Acitve = 1 Where UserID = 23398

END TRY
BEGIN CATCH

    SELECT 
        ERROR_NUMBER() AS ErrorNumber
       ,ERROR_SEVERITY() AS ErrorSeverity
       ,ERROR_STATE() AS ErrorState
       ,ERROR_PROCEDURE() AS ErrorProcedure
       ,ERROR_LINE() AS ErrorLine
       ,ERROR_MESSAGE() AS ErrorMessage;

    IF @@TRANCOUNT > 0
        ROLLBACK TRANSACTION

END CATCH

IF @@TRANCOUNT > 0
    COMMIT TRANSACTION