In case of mechanical failures.
Pray, it will help you and calm you down. :-)
If you have a mechanical failure (e.g. random crashes, just stops working one day, weird "screeching"/"beeping" type noises), EVERY time you plug it in and turn on, you could be making it much worse. If it is very important data, I would recommend taking it to a lab / professional data recovery service.
However, if you want to do it yourself, you can summarise mechanical failure into two categories:
Spindle/inside problems or outside/controller problems.
First, Spindle/inside problems. This is the worst thing that can happen to a physical hard drive, If it is this, it really depends how bad. My favourite tool for this (not free) is R-Studio, it allows you to create an image from the drive and performs many passes*, then perform the recovery from the image.
* (I have actually had drives fail a read from a sector, but just from trying over and over, it has worked - even unplugging and plugging it back in)
Depending on how important the data is, and if you are not able to read, I would try the freezer trick. This sounds like a joke but it really is not. Put the drive in an air tight bag and stick it in the freezer for a good few hours (I usually leave it in for 6 hours or overnight), then, when you plug it in, you can get a good 15-30 minutes before it crashes again.
If it is a controller board problem then, the only way to fix it is to re-flash the drive (check manufacturers website), or most commonly, switch the controller board (Carefully) from one that is an identical model.
For flash drives, again, if important, go to a lab. If you want to do it yourself, there isn't really a lot to say.
Is the error with the controller or the memory?
Typically, if it is the controller, when you plug in the drive, nothing will happen. If it is the flash memory itself, it sort of acts like a floppy/CD drive without the media in - you can see a drive letter, but just can't access it (sometimes get the insert media warning).
If it is the memory itself, I do not know a fix.
If however it is the controller, I have only ever had luck about 40% of the time doing it myself(and it depends on the architecture of the stick). Many of the cheaper sticks you see have two boards - one is the controller and the second (not sure the technical term), is a snap on daughter board. You can usually just unplug the memory and plug it in to another board.
Usually the board doesn't even have to be from a similar drive, just try to get the chip provider correct (e.g. branding on one of the ICs), the most common one I see is from Winbond and they typically work with any memory chip.