Assistance with an encoding issue

I’ve read this thread about 20 times: https://help.octopusdeploy.com/discussions/problems/3609-ampersand-and-escaping-of-environment-variables

My issue is I’m dealing with an entity framework connection string and regardless of what I do, it gets mangled during the deploy by some kind of encoding change.

The connection string looks like this:

<add name="PMOEntities" connectionString="metadata=res://*/Models.PMOModel.csdl|res://*/Models.PMOModel.ssdl|res://*/Models.PMOModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=foo.server.org;initial catalog=PMO;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />

If I put this as an Octopus variable, it changes the & to _&amp;_ which cause the site to error out. I’ve tried replacing &quot with ‘’ (two single quotes) - and while that works if i put that in the web.config, the tentacle happily starts chopping things up again during deployment by changing one of the " (double quotes) into &quot;.

While i tend to agree with some of the posters on the aforementioned thread who suggested an option ‘this works, just use this, don’t encode it, I’m sure, leave me alone’ - I’m not looking to start another discussion. What I AM looking for is some wisdom on how to format this connection string such that it will work as an Octopus variable AND in the web.config.

Thank you for your time.

Hi Blake,

Thanks for getting in touch. That thread you linked to is a mind bender.

I think you want to use double quotes instead of &quot;
For example, the variable (I cut some out):

provider connection string="data source=foo.server.org;initial catalog=PMO;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"

In the web.config becomes:

provider connection string=&quot;data source=foo.server.org;initial catalog=PMO;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;

I hope this helps.

Cheers,
Shane

Thanks sir - i’ll try that today and report back

Blake

So when i follow this advice i get this error:

Format of the initialization string does not conform to specification starting at index 126.

The resulting connection string is encoded thusly:

<add name="PMOEntities" connectionString="metadata=res://*/Models.PMOModel.csdl|res://*/Models.PMOModel.ssdl|res://*/Models.PMOModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=foo.server.org;initial catalog=PMO;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;&quot; providerName=&quot;System.Data.EntityClient&quot;" providerName="System.Data.EntityClient" />

Unfortunately when you cut some of the fluff out, i think you cut some of the complexity out too.

Hi Blake,

In the example you just sent, it looks like the provider name is included in the connection string:

providerName=&quot;System.Data.EntityClient&quot;" providerName="System.Data.EntityClient"

I think the full escaped connection string variable you want is:

metadata=res://*/Models.PMOModel.csdl|res://*/Models.PMOModel.ssdl|res://*/Models.PMOModel.msl;provider=System.Data.SqlClient;provider connection string="data source=foo.server.org;initial catalog=PMO;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"

Which should result in:

metadata=res://*/Models.PMOModel.csdl|res://*/Models.PMOModel.ssdl|res://*/Models.PMOModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=foo.server.org;initial catalog=PMO;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;

Which exactly matches the connection string part in your original post.

Cheers,
Shane

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.