"At Gibeon the Lord appeared to Solomon during the night in a dream, and God said, 'Ask for whatever you want me to give you.'" NIV translation
This verse is amazing as, even while Solomon was in sin at the high place, God showed up in a dream. We may want to ask why God would do so and then even tell Solomon to ask for whatever he wanted. Although it is tough for us to comprehend, God knows everything about our lives even before we are born. He knew what Solomon was going to ask for and He also knew that Solomon loved the Lord.
There are many places of worship that make people feel like they have to get their act together before they attend and come to Christ. The simple fact of the matter is that we cannot "get our act together" without Christ and so He meets us where we are just as He did with Solomon.
"Solomon answered, 'You have shown great kindness to your servant, my father David, because he was faithful to you and righteous and upright in heart. You have continued this great kindness to him and have given him a son to sit on his throne this very day.'" NIV translation
Solomon begins to answer the Lord by remembering the kindness that He had shown to his father. This speaks to the fact that David had left a heritage of faith in God to his family.
That is our duty as parents and is probably what is lacking most in the world today. This is even true for Christians, today, as many leave their children a legacy of religion which is not the same as a legacy of faith in Jesus Christ.
"'Now, O Lord my God, you have made your servant king in place of my father David. But I am only a little child and do not know how to carry out my duties. Your servant is here among the people you have chosen, a great people, too numerous to count or number. So give your servant a discerning heart to govern your people and to distinguish between right and wrong. For who is able to govern this great people of yours?'" NIV translation
Solomon continues to answer the Lord by acknowledging the fact that, on his own, he is inadequate for the job of being king. We see this reaction as a pattern that occurs over and over throughout the Bible. The people that God uses in mighty ways are usually the lowly ones who can see that they are nothing without Him. With this in mind, he asks for "a discerning heart" which is commonly called wisdom. Solomon had received knowledge from David but could only receive wisdom through a personal relationship with God.
The same is true for us today as we can go to all kinds of schools for higher education but we must remember that knowledge is not the same as wisdom.