Hi, that was the problem on my moodle site too.
I do the following steps to solve it.
SELECT * FROM mdl_role_capabilities WHERE capability LIKE '%moodle/site%doany%'
this leeds to 3 entries:
(timemodified is maybe false, cause I changed the entry with roleid 5 often to reproduce the effects).
UPDATE mdl_role_capabilities SET capability ='moodle/site:doanything STRANGE error in switch role to student' WHERE id=21038
that solves the problem, but does not explain anything.
If I do the select in a fresh install, then I get:
I don't now, if I have to change the entry with ID 19828
does anybody understand the system.
Thanks to Sergio - he gives the most important hint for me.