• what is the largest name of a database on the instance?

    on first glance it looks that you have a DB name larger than 25 and its failing inserting into the temp table

    select max(len(name)) from sys.databases