2 Samuel 7:3 (ESV) … “And Nathan said to the king, “Go, do all that is in your heart, for the Lord is with you.”
We have come to one of the most important passages, not just in 2 Samuel, but in the entire Bible. David is at the pinnacle of his power. He is king over all Israel. His enemies are subdued. He desires to build a house for God in Jerusalem.
The Lord responds by saying that, instead, it is He who will build a house for David. We call the Lord’s declaration the Davidic covenant. It is the unconditional promise of an ongoing dynasty for David which will culminate in the everlasting reign of the Messiah. This promise becomes a reference point for the rest of Scripture and the basis of Israel’s hope during hard times of oppression and exile.
David is enjoying a season of prosperity and security. After years of being chased as a fugitive and hiding in caves, he is firmly established as the king over all Israel and is living in his palace in his capital city of Jerusalem. The rest that he and the nation enjoy is the fulfillment of the covenant hope of Israel (Deut. 12:10; 25:19). If you have read through this history of Israel during the times of the judges and King Saul, you will realize that such peace and security is a rare and precious thing.
In the midst of all this prosperity, David desires to build a house (temple) as a dwelling place of God (through His ark) among His people. The Law spoke of the day when God’s people would have rest and security so that a permanent place for worship would be established (Deut. 12:10–12). David’s desire is commendable. Rather than using his wealth to increase the greatness of his own name, he seeks the glory of God (Ps. 132:4–5). He acknowledges that the Lord is the author of his success and he wants to express his gratitude (5:12; Ps. 116:12).
David wisely seeks counsel from the prophet Nathan, whose initial response is very positive (v. 3). Later, Nathan receives revelation from God telling David not to build the house (vv. 4–7). How could God’s prophet be wrong? While it is true that prophecy is infallible, prophets, when not speaking under the inspiration of God, are fallible (see also 1 Sam. 1:14; 16:6–7). Nathan’s initial answer was simply his assessment of the situation based upon the worthiness of David’s desire. 
Our walk with God should be measurable in both times of hardship and in times of prosperity. In times of hardship, we should be fixed in faith upon God. In times of blessing our heart should be fixed in gratitude unto God. Where are your eyes fixed in your life today?