II Samuel 7 presents God's covenant with David as unconditional: David's dynasty will last forever, and, if his sons sin, God will discipline them, but he won't remove his love from them, as he did with King Saul. But I Kings 8:25 (and other passages) makes the covenant conditional: David's dynasty will continue forever, provided the Davidic kings obey God's commandments.
Scholars try to do various things with these passages. Some say that the unconditional covenant of II Samuel 7 was pre-exilic, whereas the conditionality that I Kings 8:25 espouses emerged after Jerusalem and the Davidic dynasty were destroyed in 586 B.C.E. Others argue that both were exilic or post-exilic, since II Samuel 7 could be messianic, an expectation that God would restore the Davidic dynasty in the future because of his faithfulness to it. Still others try to reconcile the unconditional covenant with the conditionality that certain passages attach to it.
I tend to side with the first view. My reason is that there appears to be a voice in I-II Kings that treats the Davidic covenant as unconditional: God will preserve a king on the throne of Israel, and he will save Jerusalem from her enemies, on account of his promise to David. In my opinion, the destruction of Jerusalem in 586 B.C.E. and the suspension of the Davidic line are incompatible with that.
Here are the relevant passages, and the translation is from the New Revised Standard Version:
I Kings 11:11-13: Therefore the LORD said to Solomon, "Since this has been your mind and you have not kept my covenant and my statutes that I have commanded you, I will surely tear the kingdom from you and give it to your servant. Yet for the sake of your father David I will not do it in your lifetime; I will tear it out of the hand of your son. I will not, however, tear away the entire kingdom; I will give one tribe to your son, for the sake of my servant David and for the sake of Jerusalem, which I have chosen."
I Kings 11:32: One tribe will remain his, for the sake of my servant David and for the sake of Jerusalem, the city that I have chosen out of all the tribes of Israel.
I Kings 11:34-36: Nevertheless I will not take the whole kingdom away from him but will make him ruler all the days of his life, for the sake of my servant David whom I chose and who did keep my commandments and my statutes; but I will take the kingdom away from his son and give it to you-- that is, the ten tribes. Yet to his son I will give one tribe, so that my servant David may always have a lamp before me in Jerusalem, the city where I have chosen to put my name.
I Kings 11:38-39: If you will listen to all that I command you, walk in my ways, and do what is right in my sight by keeping my statutes and my commandments, as David my servant did, I will be with you, and will build you an enduring house, as I built for David, and I will give Israel to you. For this reason I will punish the descendants of David, but not forever."
I Kings 15:3-5: He committed all the sins that his father did before him; his heart was not true to the LORD his God, like the heart of his father David. Nevertheless for David's sake the LORD his God gave him a lamp in Jerusalem, setting up his son after him, and establishing Jerusalem; because David did what was right in the sight of the LORD, and did not turn aside from anything that he commanded him all the days of his life, except in the matter of Uriah the Hittite.
II Kings 8:19: Yet the LORD would not destroy Judah, for the sake of his servant David, since he had promised to give a lamp to him and to his descendants forever.
II Kings 19:33-34: By the way that he came, by the same he shall return; he shall not come into this city, says the LORD. For I will defend this city to save it, for my own sake and for the sake of my servant David."
II Kings 20:6: I will add fifteen years to your life. I will deliver you and this city out of the hand of the king of Assyria; I will defend this city for my own sake and for my servant David's sake."