this is a long standing issue - with supposedly no way to fix it inside the software (which i don't believe at all) ...
anyway, stick to the same sequence of powering up all your MIDI gear, this should help to avoid it ... however, it also means that you have to power up all MIDI gadgets everytime even if you don't need some of them, otherwise Sonar changes the order again ...
put in a feature request - something like a
user definable permanent ordering/prioritizing of MIDI devices and I you have my vote