Some suggestions:
- You may be using more than 16 tracks on your song.
- Make sure the channel assignment is correct, for example, drums should be on midi channel 10, if you have it set to some other channel it will play funny. If the file loads and plays random notes, then your channel assignment or instrument assignment in the keyboard is not done properly.
- Do you have multiple instruments connected to Sonar? If so, before saving midi file, make sure you are selecting the first midi output if you have multiple midi outputs. I have ran into issues when I had multiple output midi interface connected to sonar and I had output two or something selected while saving the file.