I changed my camera lens while it was switched on. It was my first time doing this because I usually switch off my camera and change the lens but this has been the first time I've changed the lens while my camera was switched on. Is it dangerous? Will anything happen to my camera?
I have been changing lenses with the camera on for years, as have many thousands of others.
There is no evidence this will damage you camera in any way (there is a theory that when the camera is on the sensor is "charged" and will attract dust, but I haven't seen any evidence of that either).
There's an old story about a family recipe for baking ham that had been handed down through several generations. It was the best tasting ham anyone who had tried it had ever had! The first step was to always cut the top three inches off the end of the ham before placing it in the pan. Anyone who has ever tried to cut through a ham bone with normal kitchen utensils knows this is not an easy task. But every generation of cooks in the family faithfully followed the recipe and dutifully removed the top three inches each time before cooking a ham.
One time the family was gathered for a big, festive meal at the great-granddaughter's palatial new home. Far different than the humble origins the family had come from several generations earlier, her elder relatives were amazed at the spacious, fully equipped kitchen that would have sufficed for a small restaurant. She had prepared the ham exactly as the instructions had been handed down through the years. Her great-grandmother was the guest of honor. As the ham was set upon the banquet table she was invited to cut the first slice from the ham. She looked at it for a moment and then turned and asked her great-granddaughter why in the world she had removed the top portion of the ham before cooking it? Her young host, almost in tears from the thought of having disappointed her guest, replied, "That's the way my mother said her mother taught her, and said that was the way you had taught her mother." The elderly lady laughed and laughed. After she finally recomposed herself she explained, "Yes we did. We were so poor and our oven was so small and the pan so little that we always had to cut a few inches off for it to fit!"
Some designs in the distant past when electricity first began flowing through the connection between cameras and lenses may have been susceptible to errors if lenses were changed when the power was on. Early digital designs may have kept the sensor energized the entire time the camera was powered up. As far as I am aware, neither of these is any longer the case. Current designs include features that inform the camera when a lens is no longer connected, usually through the design of the lens/camera interface.
There are some potential scenarios where you might do harm by removing a lens when the camera is powered up, but they would be few and far between. What such scenarios are would vary from one design to the next. Cameras with mechanical linkages that are active (e.g. a focus motor in a body is actively moving the focus elements of a lens) when the lens is detached might cause mechanical damage or excessive wear. (One of the weaknesses of the Nikon and similar systems is that the aperture linkage is susceptible to being bent if a lens is attached incorrectly, but that is true whether the camera is turned on or off.) Cameras capable of updating firmware of a lens shouldn't be disconnected (or turned off) during the middle of a firmware update. When the shutter is open during a long exposure, it is probably not the best idea to remove the lens, especially in a dusty environment. But the potential for harm if the camera is merely powered on but not actually doing anything is pretty much non-existent.
Some safety instructions for products are like the recipe for baked ham in the story above. They survive in the precautions section of the user manual even though the design has been changed several times and the warning may no longer be applicable.
I do professional photography on the side and I do nothing but change the lens with the power on. I don't think I have changed lenses with the power off once on my camera ever.
There's no particular reason that I have to change with the power on, but there's no reason not to either and since I only change my lens when a situations arises when I'm shooting, my camera is already on.
While the theory is that the sensor will attract dust when it is on, that doesn't really hold much weight because there is no actual evidence that it does so. Even if there was, it would require every manufacturer out there to be idiots when it comes to design because your camera knows when a lens isn't attached and could do the shutdown of the sensor for you if it was a problem.
Now on the flip side, turning the camera off for every lens change DOES require your camera to power cycle and while I don't think it would be much wear and tear, the wear and tear of the extra power cycles is probably worse than any amount of dust attraction. (Though I wouldn't be surprised if neither actually has a meaningful, measurable impact.)