There are two fundamental errors in your post:
1) You don't include the error message that you get.
2) You do not have a PRINT of the generated SQL.
There are also a few more flaws in your script:
1) The variable declared @db1 is not declared. (You declare it on top, but you have multiple batches, and a variable only lives for a batch.)
2) Your @SQL4 variable is way too short, and could be truncated if @db1 would have a longer value. Always use nvarchar(MAX) for variables you use for dynamic SQL.
3) Your @SQL3 is fairly meaningless. The effect of USE is reverted when you exit the scope the USE was executed in. And you dynamic SQL is a scope of its own. (Think of it as a anonymous stored procedure.)