Thats because the SP is running in dbThree - when you use
EXEC [dbThree].[dbo].GetDatabaseName
You are effectively issuing a
USE dbThree
command for the duration of the
EXEC
If you want the "original" database name, then you need to add the same procedure in all the DBs, and remove any qualification when you
EXEC
it.