What are the challenges you face when working across database platforms? Take the survey
Options

Entity Framework Connection String Variable

tomorgantomorgan Posts: 4
edited October 3, 2013 6:31AM in Deployment Manager
Hi there,

Apologies if this has come up before, but the search didn't reveal anything so hopefully this keyword-stuffed title will help anyone else in the future!

I'm evaluating Deployment Manager at the moment: so far, so awesome :)

However, I have a question about the best way to create variables which represent SQL connection strings as used by Entity Framework. The structure of the connection key in the web.config is a little different. Specifically, here's an example:
<add name="Entities" connectionString="metadata=res://*/EntityFrameworkModel.DatabaseModel.csdl|res://*/EntityFrameworkModel.DatabaseModel.ssdl|res://*/EntityFrameworkModel.DatabaseModel.msl;provider=System.Data.SqlClient;provider connection string="data source=SERVERNAME;initial catalog=DBNAME;Trusted_Connection=True;MultipleActiveResultSets=True;App=APPNAME"" providerName="System.Data.EntityClient" />

As you can see, there's use of embedded quotes, using the " escape string.

I read in your docs that you shouldn't use escape characters in variables, to avoid double escaping and in testing, that's exactly what's happened (producing something like "" instead of &quote;")

What's the best way of writing this in the variable string to output a connection string like the above?

Thanks for any help.

-tom

Comments

  • Options
    Hi Tom,
    Sorry for the delay in replying. If you put the actual quote in the variable value rather than the xml representation of that quote.
  • Options
    Hi,

    Thanks for your reply. However... I want the xml representation to be persisted. The example string is how the key should look after it's been though DM. Notice that there's an escaped quotation string within the standard quotation. That's what I can't work out what to do.
  • Options
    Hi Tom,
    If you add a variable called Entities to your project with the value specified as:
    metadata=res://*/EntityFrameworkModel.DatabaseModel.csdl|res://*/EntityFrameworkModel.DatabaseModel.ssdl|res://*/EntityFrameworkModel.DatabaseModel.msl;provider=System.Data.SqlClient;provider connection string="data source=SERVERNAME;initial catalog=DBNAME;Trusted_Connection=True;MultipleActiveResultSets=True;App=APPNAME"
    

    Then it will look exactly as you want it to after it has been through Deployment Manager. So remove the surrounding quotes and replace the xml quote tags with an actual ". Deployment Manager understands that the config file is xml and escapes the characters accordingly.
    Hope that helps.
  • Options
    Thanks for your reply: that makes a lot of sense, and works exactly as you describe.

    The bit I was surprised about was that I didn't need to include the providerName attribute in the variable - I was worries that DM would remove it when updating the variable on the deployment machine, but that wasn't the case.

    Thanks again for your help.

    -tom
  • Options
    Glad it is working for you.
Sign In or Register to comment.