the gemara implies that david was ultimately forgiven for his sin as witnessed by the gates of the temple opening when his son on his third try employed david's merits successfully. how may this tack be reconciled with the gemara elsewhere which states that only one who errs says david sinned?
The Gemara (Shabbos 58a) that says David ha'Melech did not sin is referring to his conduct with Bas-Sheva (see Rashi there, DH David, who says that David did not sin "with the transgression of Eshes Ish"). The verses clearly state, though, that he did sin in other matters -- specifically with regard to the death of Uriyah.
Mordecai
I THOUGHT DAVID DID NOT SIN BECAUSE OF URI WAS " MORED MEMALCHUT" AS STATED IN KIDDUSHIN 43
The prophet exclaimed and said, "And him (Uriyah) you killed with the sword of the people of Amon!" How can it be that David was completely innocent? The answer is that David did not commit an actual sin of Ervah, nor did he commit an actual sin of Retzichah (murder). Rather, he sinned with "Lo Tachmod Eshes Re'echa," and by causing Uriyah to rebel against the king and to be killed because of his rebellion, as we find in Tanach. David was held accountable for those acts as if they were very severe transgressions because of the Madreiga which he was on (as the Gemara says in Bava Kama 50a).