Car won't run with crankshaft position sensor plugged in on 2003 Nissan Maxima

I have a 2003 Maxima 6 speed, I just replaced the engine, at first I kept getting the p0335 code, but the car would take a long time to start but eventually it would start and run strong. I realized the reason for the code is I mixed up the sockets for the Crank Position with the O2 sensor. After correcting the crossing the car will now start right up but idle like hell for a few seconds and die, I tried pressing the accelerator and that doesn't help. I have an OBD2 scanner and I checked the readings from all the sensors and everything seems to be responding ok. Any ideas? I went through the, Accelerator Pedal Release Position Learning Procedure for 2K2+ and the Throttle Valve Closed Position Learning Procedure for 2K2+ still with no luck, any suggestions on where to go from here? If I unplug the crank sensor it runs fine just takes a while to start.

Thanks everyone for your help.

Asked by for the 2003 Nissan Maxima
When you swapped engines did you have to do anything with the timing chain set-up? With your scanner what does it show the base timing at and is it steady? What are you getting from the knock sensor?What does MAF say with Key-on ,engine-off?Also map/bap sensor readings with engine off?
I didn't mess with the timing at all, also when the crankshaft sensor is disconnected the car runs great. I'll check the readings with the key on engine off and let you know what everything says.
Another thought , when you swapped engines did you use the sensors that came with the engine you bought (I'm assuming used) or did you swap over the sensors from your original engine?
I swapped the ones from my old engine.
WELL.....that ruins one theory I had.
Ok so I went and got new crank and cam sensors from Nissan this time and ended up with the same result here are the readings from my scanner with key on engine off at room temperature:

eng speed 0
calc load 0
MAF (LB/M) .02
Coolant 102 F
IAT 102 F
IGN Advance 63.5
Veh Speed 0 MPH
Fuel sys 1 Open
Fuel sys 2 open
O2S11 0
ST FTRM11 -100
o2s12 .290
o2s21 0
ST FRM21 -100
O2s22 .430
Sorry to drag this out , but 1 more question, why was engine replaced?
old on threw a rod
On the IGN Advance, does it change when you unplug it?...same conditions KOEO.I see the MAF , but I don't see a barometric pressure sensor reading. I deal with Honda primarily but those and most other brands I've dealt with had that also , just not the manifold pressure sensor.Could just be I'm a moron though.