It took me 12 years to sell, and the book I sold was the sixth full manuscript I'd written.
Here are the details: I wrote steadily for about six years, getting lots of rejections on full manuscripts and partials. I was doing well in contests, though, (placing and/or winning pretty regularly) but not selling. I finally got discouraged and gave up for about three years. During that time when I wasn't writing, I was absolutely miserable. I kept thinking about writing every day. So I finally decided that I might as well start up again since I was so unhappy NOT writing. It still took me another three years to sell. Unfortunately, after selling two books I got three more rejections. I am now under contract again, but this experience has taught me to never take anything for granted. There is absolutely no guarantee of success during any step of this journey - before or after selling a book.
As an aside, the first book I sold was rejected by an editor in the same house that eventually bought it. Fortunately, the editor who bought it had seen the story in two contests, loved it, and was able to override the rejection by the first editor. It sold with no changes whatsoever. The editor who rejected it said that the story was "too depressing." This story (Where He Belongs) won the Golden Heart, and went on to win or final in eight other contests for published books.