Wednesday, November 16, 2022

How to Get the Last Day of the Month in T-SQL

We’ll use the function EOMONTH() to find the last day of the month.

DECLARE @fromdate DATETIME, @EOMMonthdate DATETIME

SET @fromdate = '11/01/2022'

SET @EOMMonthdate = EOMONTH(@fromdate,0) -- for current month

SELECT @EOMMonthdate as lastdayOfthemonth
  

If you want to return the last day of the second, third, etc. month from a given date, use EOMONTH()’s optional second argument: the number of months to add. Look at the examples for last day of next month or last day of the previous month.

DECLARE @fromdate DATETIME, @EOMMonthdate DATETIME

SET @fromdate = '11/01/2022'

SET @EOMMonthdate = EOMONTH(@fromdate,1) -- for next month last day

SELECT @EOMMonthdate as nextMonthLastDayOfthemonth

SET @EOMMonthdate = EOMONTH(@fromdate,-1) -- for previous month last day

SELECT @EOMMonthdate as previousMonthLastday
  

Hope this helps!!

Visual Studio Debugging Windows: Watch, Locals, Autos, Immediate, Call Stack and Threads

The Watch Window

The Watch Window allows you to see value of variables and expressions while debugging. It’s kind of like the DataTip you get when hovering over a variable, except that you can write any expression you want. It’s available from Debug | Windows | Watch | Watch 1 or Ctrl + Alt + W + 1.

There are 4 watch windows in Visual Studio, which you can use in different contexts (Watch 1, Watch 2, etc.).

Any expression can be entered into the watch window. The same rules apply to expressions as to code. So if you write an illegal expression, you’ll see the same compiler error.

To add items to watch do any of the following:

  • Write them manually in a new row of the Watch window
  • Right-click on a variable choose “Add Watch” in the context menu
  • Right-click on a variable in the DataTip and choose “Add Watch”
  • “Add Watch” button from QuickWatch

When to Use the Watch Window:

While the DataTip and QuickWatch are more popular, the watch window is very useful when you need to re-evaluate the same variables and expressions multiple times. This happens if you hit the same breakpoint over and over again, or different breakpoints in the same class. The most common scenario is with a breakpoint inside a loop

The Immediate Window

The immediate window is available in the menu from Debug | Windows | Immediate or Ctrl + Alt + i. You can type in any expression and the immediate window will evaluate. It’s kind of like the Watch window, but it acts more like a command line window in Windows or Linux.

For me, the immediate window was always more convenient than the Watch or QuickWatch windows.

  • Like in command line interfaces, you can use the Up/Down arrow keys to paste previous expressions.
  • To clear the window, right-click on it and select “Clear All”.

Locals and Autos Windows

VS offers 2 automatic-watch tool windows: The Locals and Autos windows.

The Locals will show local variables of the current scope. It usually starts with this, which represents the current class.

The Autos window will show all variables used in the current line and in the previous line. These could be local variables, class members or static variables. The Autos also shows values returned from methods, which is useful at times

  • In both Locals and Autos, you can double click on any Value field and change the variable’s value. This will actually its value, causing a possibly unwanted side effect.
  • Search works same as in the Watch window.

Call Stack Window

One of the most useful tool windows is the Call Stack Window. It shows the chain of methods that called one another, up to the the currently debugged method

Threads Window

The Threads Window is the final tool window in what I call the Truly Vital Debugging Windows group. This window shows all the currently active threads, and allow to switch between them.

 

Sunday, October 09, 2022

Some facts about Vedic Mathematics

Vedic Mathematics makes Mathematics Magical. The subject is unique in itself.

Vedic Mathematics helps to solve mathematical calculations easy and fast.

With Vedic Mathematics we can perform calculations mentally or in s single or minimum steps.

Some unique facts are:

1. In addition, we don't need multiple carry overs.

2. In subtraction, there is no concept of borrow.

3. 16 sutras and 16 sub sutras form the base which can be put to use in almost any branch of mathematics.

4. Composed in maximum 120 Sanskrit words.

5. These sutras can be applied to various operations too.

6. Totally Indian system

7. Use of decimal system well defined.

8. Use of zero originated and used by the system.

9. The system of mathematics is popularized as Vedic mathematics.

10. Sharpens memory as propagates think without ink.

11. Uses the intricacies of formulate derived and put to use which is not so prevalent in Western mathematics.

12. The concept of Vinculum numbers helps to convert bigger number to smaller and thus makes calculations easy and fast.

13. The concept of Digital Root or Navashesh or Digital Sum helps to verify our answers in seconds.

Friday, October 07, 2022

How to increase file upload size limit in ASP.NET Core

ASP.NET Core 2.0 or 2.1 enforces 30MB (~28.6 MiB) max request body size limit, be it Kestrel and HttpSys. Under normal circumstances, there is no need to increase the size of the HTTP request. But when you are trying to upload large files (> 30MB), there is a need to increase the default allowed limit.

Kestrel is a cross-platform web server for ASP.NET Core and that’s included by default in ASP.NET Core project templates. Kestrel can be used as a standalone server or with a reverse proxy server, such as IIS, Nginx, or Apache

Hosted on IIS

Remember in the ASP.NET, we used to set maxRequestLength in web.config file to increase the default limit of 4MB. Like,

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
     <security>
      <requestFiltering>
        <requestLimits maxAllowedContentLength="4294967295"  />
      </requestFiltering>
    </security>  
   </system.webServer>
</configuration>
  

Similarly, for ASP.NET Core application, we can increase the default limit of 30MB by setting maxAllowedContentLength property in the web.config file. The default ASP.NET Core application template doesn’t create the web.config file. It is created when you publish the application. However, you can also add it manually (if not present) to the root of the application with the following code.

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.web>
    <authentication mode="Windows" />
    <httpRuntime enableVersionHeader="false" />
  </system.web>
  <!-- To customize the asp.net core module uncomment and edit the following section. 
  For more info see https://go.microsoft.com/fwlink/?linkid=838655 -->
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true">
      <remove name="WebDAVModule" />
    </modules>
    <handlers>
      <remove name="aspNetCore" />
      <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
    </handlers>
    <!-- processPath="dotnet" arguments=".\Mobility.Core.Web.API.dll"  update with these values on stage or prod servers-->
    <aspNetCore requestTimeout="00:20:00" processPath="dotnet" arguments=".\myCoreWeb.Core.Web.API.dll" stdoutLogEnabled="true" stdoutLogFile=".\logs\stdout">
      <environmentVariables />	 
    </aspNetCore>
	 <security>
        <requestFiltering>
          <!-- This will handle requests up to 50MB -->
          <requestLimits maxAllowedContentLength="52428800" />
        </requestFiltering>
      </security>
  </system.webServer>
</configuration>
<!--ProjectGuid: 82a05c43-b244-4222-a1ff-ebe99b445a14-->

Hope this helps!

Open Live Writer–Google Blogger login issues

When it comes to blogging I am big fan of Open Live Writer aka OLW. Recently I had issues with google connections. May be some of you might have same problems connecting to blogger.

The Volunteers at Microsoft has released a new version of OLW that has fixed the connection issue. OLW now works fine with Google Blogger v3. I have included below the direct link to the team's frequently updated setup copy called "Nightly" which contains several unreleased features that you can try out. Download the latest version from the link below.

I have found this information at GitHub forums related to OLW https://github.com/OpenLiveWriter

Download OLW (Build 0.5.1.2) - Nightly