avrdude: ser_open(): can't open device "\\.\COM5": Access is denied.

I am using windows 7 Service pack 1 Arduino IDE 1.8.9 Arduino Uno R3 (Genuino Uno) Usb cable for connection

When i upload a reset arduino sketch then the following error in displayed:-

Arduino: 1.8.9 (Windows 7), Board: "Arduino Uno"

Sketch uses 2084 bytes (6%) of program storage space. Maximum is 32256 bytes.
Global variables use 218 bytes (10%) of dynamic memory, leaving 1830 bytes for local variables. Maximum is 2048 bytes.
C:\Users\Nextprint\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17/bin/avrdude -CC:\Users\Nextprint\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17/etc/avrdude.conf -v -p atmega328p -c arduino -P COM5 -b115200 -D -Uflash:w:C:\Users\NEXTPR~1\AppData\Local\Temp\arduino_build_627187/reset_prog.ino.hex:i 

avrdude: Version 6.3-20190619
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2014 Joerg Wunsch

An error occurred while uploading the sketch
         System wide configuration file is "C:\Users\Nextprint\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17/etc/avrdude.conf"

         Using Port                    : COM5
         Using Programmer              : arduino
         Overriding Baud Rate          : 115200
[b]avrdude: ser_open(): can't open device "\\.\COM5": Access is denied.[/b]

avrdude done.  Thank you.

Previously I had updated Makeblock XY .hex firmware and i wanted to reset the arduino board so that i can enter another firmware and this error occured.

Please give me a correct 100% working solution to the problem.

Thank You .

Does this happen 100% of the time, or occasionally?

If 100% of the time, there may be permission issues on opening ports. On Linux your login must be a member of the group the port is in, typically 'plugdev'. On Windows this is usually only a problem if your login does NOT have local administrator privileges and an IT department has locked out opening ports.

If it is occasional, it sounds like something I have seen:

I get that error (and similar 'can't open /dev/ttyACM0' on Linux) occasionally, running 1.8.12 Arduino IDE.

I have found that the IDE gets into a weird state where it has apparently opened the port already and locked it for exclusive use, but has lost track of that fact.

Closing all IDE windows and re-opening the project fixes the problem.

NB - In a very few cases under Windoze I have had to reboot my computer in order to get the com-port to work again.