The short answer
It is not in the canon. Snopes and Quote Investigator both confirm that across the fifty-six short stories and four novels Arthur Conan Doyle wrote, Sherlock Holmes never says these four words in that order. The phrase was, as Quote Investigator puts it, synthesised by readers and enthusiasts and then assigned to the character.
How close Conan Doyle actually got
Tantalisingly close, which is why the false memory is so durable. In the 1893 story The Adventure of the Crooked Man, Holmes both uses the word elementary and addresses Watson as my dear Watson — but the two appear about fifty-two words apart. In The Adventure of the Missing Three-Quarter (1904) he says exactly, my dear Watson. The raw materials are all there; the sentence is not.
Who finished the job
The stage actor William Gillette, who played Holmes from 1899 and invented much of the popular image, is often credited with the line — though Snopes notes it appears in no published version of his script. Quote Investigator finds a close match in print by 1902 and an exact one by 1908. P. G. Wodehouse used it in Psmith, Journalist (1915) and Agatha Christie in The Secret Adversary (1922). The 1929 film The Return of Sherlock Holmes, with Clive Brook, closed on the line and sealed it permanently.
A quotation with no author
This is the purest case in our collection. There is no misattributed individual to correct, because the phrase was not written by anyone in particular — it condensed out of a reading public that had absorbed a character so thoroughly it could finish his sentences for him. It is folklore about a fictional man, and it is now more famous than any line he was actually given.
What this means for your English
Say it aloud and you can hear why it won: elementary is four syllables of dactylic swagger, and my dear Watson lands as a soft, condescending pat. English speakers remember rhythm far more reliably than wording — which is precisely how misquotations form, and why a well-shaped sentence will always beat an accurate one in the memory.