Original von swiki
(we have been talking on another forum, it is FriendlyKiwi here 
OK, done some research about your problem
Based on your N42 motor controlled by the ME9 engine management system (DME).
[quote from BMW manuals]
Battery voltage monitoring
The battery voltage is continuously monitored in the DME. At a battery voltage of less than 2.5 V or greater than 24 V, a fault is entered. The diagnosis only becomes active 3 minutes after engine start-up. This means that the effects of the starting process or starting assistance on the battery voltage are not regarded as a fault.
Fuel Pump
The fuel pump is located in the fuel tank. It is switched on and off by means of a relay and delivers the fuel via the fuel filter to the fuel distributor pipe.
Fuel pump relay
The control unit can only monitor activation of the relay but not of the pump itself. A safety circuit ensures the relay can only be activated with the engine running and only shortly after switching the ignition lock to position 2 in order to build up pressure.
Once the engine shuts down, the DME control unit no longer recognized engine speed and immediately switches off the relay. This ensures that the fuel pump cannot continue running when the engine turned off.
[end quote]
[here is my analysis]
The DME (digital motor electronics) controls the fuel pump in the E46 via a relay, K96
The fuel pump is protected by fuse F54, 15A
Before you start hunting for weasel damage, I recommend:
1. Replace fuse F54 (15A) with a new (or spare) one. Sometimes fuses develop hairline cracks that cause problems with vibration and heat. The fuse is very cheap to replace, try a new one.
F54 is located in the fuseholder above the glovebox.
2. For the same reason, replace fuse F3 (20A). This supplies power to the fuel pump relay, the secondary air pump relay and the AC compressor relay. If this fuse is cracked, you will loose power to the fuel pump relay. F3 is in the fuse carrier in the engine bay electronics box.
3. Replace the fuel pump relay K96. Tarnished or burnt relay contacts cause many electrical problems. If the fuel pump looses power then fuel pressure will be lost and the engine will stop. A new, quality BMW relay is cheap and easy to fit. Relay K96 is located behind the glovebox, the leftmost of 4 relays.
4. Check loom connector X6021 for corrosion and water damage or loose fitting. it is located in the electronics box in the engine bay where the DME is. Power to the fuel pump (and secondary air pump relay and AC compressor relay) go through pin 2 of X6021 (red wire with white stripe). If this has a bad connection, power to the fuel pump relay might become intermittent.
5. I think it is impossible to have weasel damage in the fuel pump wiring, as the relay and fuse are in the glovebox, and the wiring from the relay to the pump goes through the inside of the car.
However, the DME is in the engine bay and the DME controls the fuel pump relay. Some wiring from the DME to the inside of the car may be exposed. This is where one should inspect very very carefully.
7. A way to diagnose the fuel pump: the fuel pump has 2 x wires on the fuel pump connector. Blue/white (12V power) and brown (ground)
Run 2 x temporary wires from the fuel pump connector to a small 12V 5W light bulb that can be placed in view of the driver. The light bulb will light when the fuel pump is running. Drive the car, and monitor the light bulb. If the light goes off and then the engine fails, it proves lack of power to the fuel pump.
Well, that probably exhausts all possible fuel pump power issues - if you work through the above and change fuses and relay and check the loom connector and monitor the pump, you will know for sure the state of your fuel pump.
Swiki aka FriendlyKiwi