I store several different connection strings in my web.config for development and testing. All but one is commented out so I can change info as needed.
When I publish, I
Instead of transforming the string, or using "Remove" and "Insert" clean the section try using "Replace".
For example:
You can configure this section exactly how you want it, even if that means you add new comments.