Cannot upload code to Arduino over Bluetooth - access to COM port denied

Hello,

I am trying to upload code to my Arduino over my HC-05 bluetooth module. I have been following this guide to set up the bluetooth module. I was able to reach the final step, but whenever I attempt to upload the blink sketch to the Arduino Uno, I get this output from the IDE:

Arduino: 1.8.13 (Windows 10), Board: "Arduino Uno"

Sketch uses 924 bytes (2%) of program storage space. Maximum is 32256 bytes.

Global variables use 9 bytes (0%) of dynamic memory, leaving 2039 bytes for local variables. Maximum is 2048 bytes.

C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avrdude -CC:\Program Files (x86)\Arduino\hardware\tools\avr/etc/avrdude.conf -v -patmega328p -carduino -PCOM3 -b115200 -D -Uflash:w:C:\Users\DON'TM~1\AppData\Local\Temp\arduino_build_336232/Blink.ino.hex:i 



avrdude: Version 6.3-20190619

         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/

         Copyright (c) 2007-2014 Joerg Wunsch



         System wide configuration file is "C:\Program Files (x86)\Arduino\hardware\tools\avr/etc/avrdude.conf"



         Using Port                    : COM3

         Using Programmer              : arduino

         Overriding Baud Rate          : 115200

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






avrdude done.  Thank you.



Problem uploading to board.  See http://www.arduino.cc/en/Guide/Troubleshooting#upload for suggestions.

I can tell that my PC is communicating with the Bluetooth module, because the HC-05 module LED behaves differently while uploading the code.
What should I do to remove this error so I can upload code to the Arduino?

Additional notes:
-I have also tried this with a Mega 2560, and it also didn't work - the code would compile but fail to upload in a similar manner.
-When I was running the AT commands on the bluetooth module, the final command

AT+INIT

returned error(17). This error appears to mean that this command was already executed, but I don't know if this would have caused the issue I am experiencing now.

Thanks in advance!

Not sure about the access denied; check Windows event logs if they reveal something.

However, you should disconnect the bluetooth module from TX and RX while uploading. For a Mega, try using one of the other three serial ports.

Note:
A 'similar' manner does not mean much. It's either the same or it's different in which case you should post the new error.

sterretje, I'm trying to upload sketches to the Arduino through the Bluetooth module. This is why I have it connected to the RX and TX pins.
As for the Mega 2560, I tried uploading the code via bluetooth (with the bluetooth module connected) and this happens:

Arduino: 1.8.13 (Windows 10), Board: "Arduino Mega or Mega 2560, ATmega2560 (Mega 2560)"

Sketch uses 1536 bytes (0%) of program storage space. Maximum is 253952 bytes.

Global variables use 9 bytes (0%) of dynamic memory, leaving 8183 bytes for local variables. Maximum is 8192 bytes.

C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avrdude -CC:\Program Files (x86)\Arduino\hardware\tools\avr/etc/avrdude.conf -v -patmega2560 -cwiring -PCOM3 -b115200 -D -Uflash:w:C:\Users\DON'TM~1\AppData\Local\Temp\arduino_build_255865/Blink.ino.hex:i 



avrdude: Version 6.3-20190619

         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/

         Copyright (c) 2007-2014 Joerg Wunsch



         System wide configuration file is "C:\Program Files (x86)\Arduino\hardware\tools\avr/etc/avrdude.conf"



         Using Port                    : COM3

         Using Programmer              : wiring

         Overriding Baud Rate          : 115200

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




avrdude: ser_drain(): read error: The handle is invalid.




avrdude: ser_send(): write error: sorry no info avail

avrdude: stk500_send(): failed to send command to serial port

avrdude: ser_recv(): read error: The handle is invalid.




avrdude: stk500v2_ReceiveMessage(): timeout

avrdude: ser_send(): write error: sorry no info avail

avrdude: stk500_send(): failed to send command to serial port

avrdude: ser_recv(): read error: The handle is invalid.




avrdude: stk500v2_ReceiveMessage(): timeout

avrdude: ser_send(): write error: sorry no info avail

avrdude: stk500_send(): failed to send command to serial port

avrdude: ser_recv(): read error: The handle is invalid.




avrdude: stk500v2_ReceiveMessage(): timeout

avrdude: ser_send(): write error: sorry no info avail

avrdude: stk500_send(): failed to send command to serial port

avrdude: ser_recv(): read error: The handle is invalid.




avrdude: stk500v2_ReceiveMessage(): timeout

avrdude: ser_send(): write error: sorry no info avail

avrdude: stk500_send(): failed to send command to serial port

avrdude: ser_recv(): read error: The handle is invalid.




avrdude: stk500v2_ReceiveMessage(): timeout

avrdude: ser_send(): write error: sorry no info avail

avrdude: stk500_send(): failed to send command to serial port

avrdude: ser_recv(): read error: The handle is invalid.




avrdude: stk500v2_ReceiveMessage(): timeout

avrdude: stk500v2_getsync(): timeout communicating with programmer



avrdude done.  Thank you.



the selected serial port 

 does not exist or your board is not connected