Changing string in all objects in all databases on one server
sp_msforeachdb is undocumented. There are viable alternatives to it.

Try changing:

SET @SQL='select ''?'' as DbName, o.name as ObjectName, o.type_desc as 
 ObjectType, m.definition as Definition from [?].sys.sql_modules m inner join sys.objects o on m.object_id = o.object_id where m.definition like ''%MyString%'''

to:

SET @SQL='USE [?]; select Db_Name(), o.name as ObjectName, o.type_desc as ObjectType, m.definition as Definition from sys.sql_modules m inner join sys.objects o on m.object_id = o.object_id where m.definition like ''%MyString%'''

As originally written, the @SQL's sys.objects will reference the database being used for sp_msforeachdb's execution and thus the statement's 2 object_id values may or may not join.