I know I'm very late to this game, but hopefully my reply will help others. I just had this issue happen to me also on Sonar Platinum Producer Edition after years of it working perfectly. I too went crazy trying to figure it out, which luckily I did fairly quickly. The problem in my case started after I unplugged my NanoKontrol2. Just like everyone else experiencing this issue, I could see MIDI activity in the task bar and also stand-alone virtual instruments worked fine outside of Sonar. I've had an AlphaTrack for years and regardless of if it was plugged in or not this had never happened, so it took me a minute to figure out the issue. Now that I think of it, I had also used the NanoKontrol2 before and unplugged it, and I didn't have this issue.
In my case the culprit was MMcL Mackie Control which I downloaded and installed a few weeks back. Now, I'm not 100% sure if the problem was caused by this program specifically or if this happens when you're using other control surfaces that use Mackie Control and then disconnect them from your system, but MMcL Mackie Control reassigned its midi input to my USB MIDI cable once the NanoKontrol2 wasn't plugged in. I downloaded the software following a link on this forum from one of our fellow users, msmcleod, and it works beautifully with the NanoKontrol2, so kudos to msmcleod. The solution is very simple. Go to Preferences and under Controller/Surface find MMcL Mackie Control (or any other control surface) and make sure that under input it isn't using the input your MIDI controller is connected to. In my case it was my USB MIDI cable. Like I said, I'm not sure if the issue is specifically with MMcL Mackie Control or with the Mackie protocol in general, but I had used my NanoKontrol2 before and unplugged it and this had never happened until I installed MMcL Mackie Control a few weeks ago. Hope this helps someone and thanks to msmcleod for the NanoKontrol2 software.