Sam had the ring for just a moment before he started fantasizing about leaving to come back with an army of hobbits to take mordor by force and making it into a garden. He barely managed to give it back to Frodo who had been carrying it all this time while it slowly chipped away at his mind having to constantly remind himself to not give in to its temptations while it was punishing him for not doing so with constant torment.
But sure he was just useless, go Sam whoo!
The book. “Moment” as in a short span of time before he started fantasizing, I believe it was when Frodo was unconscious before the arrival of the orcs and the realization that he was alive, though I’m prone to misremembering. He caught himself in his folly and did great deeds, I just wanted to emphasize how immediate and potent the effect was not to downplay Frodo’s deeds and sacrifice.
Gandalf did touch it in the book, that part was the movies, though he wouldn’t take possession of it, even temporary.