Entity Framework Connection String Variable

Automated deployment for web applications and databases

Entity Framework Connection String Variable

Postby tomorgan » Tue Oct 01, 2013 10:57 am

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:

Code: Select all
      <add name="Entities" connectionString="metadata=res://*/EntityFrameworkModel.DatabaseModel.csdl|res://*/EntityFrameworkModel.DatabaseModel.ssdl|res://*/EntityFrameworkModel.DatabaseModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=SERVERNAME;initial catalog=DBNAME;Trusted_Connection=True;MultipleActiveResultSets=True;App=APPNAME&quot;" providerName="System.Data.EntityClient" />


As you can see, there's use of embedded quotes, using the &quot; 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 &amp;quot;&quot; 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
tomorgan
 
Posts: 3
Joined: Tue Oct 01, 2013 10:49 am
Location: Norwich, Norfolk

Postby Emma A » Wed Oct 02, 2013 12:44 pm

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.
Emma A
 
Posts: 40
Joined: Mon Mar 30, 2009 2:53 pm

Postby tomorgan » Wed Oct 02, 2013 8:05 pm

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.
tomorgan
 
Posts: 3
Joined: Tue Oct 01, 2013 10:49 am
Location: Norwich, Norfolk

Postby Emma A » Thu Oct 03, 2013 9:07 am

Hi Tom,
If you add a variable called Entities to your project with the value specified as:
Code: Select all
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.
Emma A
 
Posts: 40
Joined: Mon Mar 30, 2009 2:53 pm

Postby tomorgan » Thu Oct 03, 2013 10:50 am

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
tomorgan
 
Posts: 3
Joined: Tue Oct 01, 2013 10:49 am
Location: Norwich, Norfolk

Postby Emma A » Thu Oct 03, 2013 11:31 am

Glad it is working for you.
Emma A
 
Posts: 40
Joined: Mon Mar 30, 2009 2:53 pm


Return to Deployment Manager

Who is online

Users browsing this forum: No registered users and 0 guests

cron