Red Gate forums :: View topic - Entity Framework Connection String Variable
Return to www.red-gate.com RSS Feed Available

Search  | Usergroups |  Profile |  Messages |  Log in  Register 
Go to product documentation
Deployment Manager
Deployment Manager forum

Entity Framework Connection String Variable

Search in Deployment Manager forum
Post new topic   Reply to topic
Jump to:  
Author Message
tomorgan



Joined: 01 Oct 2013
Posts: 3
Location: Norwich, Norfolk

PostPosted: Tue Oct 01, 2013 10:57 am    Post subject: Entity Framework Connection String Variable Reply with quote

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 Smile

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:
      <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
Back to top
View user's profile Send private message
Emma A



Joined: 30 Mar 2009
Posts: 40

PostPosted: Wed Oct 02, 2013 12:44 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
tomorgan



Joined: 01 Oct 2013
Posts: 3
Location: Norwich, Norfolk

PostPosted: Wed Oct 02, 2013 8:05 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
Emma A



Joined: 30 Mar 2009
Posts: 40

PostPosted: Thu Oct 03, 2013 9:07 am    Post subject: Reply with quote

Hi Tom,
If you add a variable called Entities to your project with the value specified as:
Code:
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.
Back to top
View user's profile Send private message
tomorgan



Joined: 01 Oct 2013
Posts: 3
Location: Norwich, Norfolk

PostPosted: Thu Oct 03, 2013 10:50 am    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
Emma A



Joined: 30 Mar 2009
Posts: 40

PostPosted: Thu Oct 03, 2013 11:31 am    Post subject: Reply with quote

Glad it is working for you.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic All times are GMT + 1 Hour
Page 1 of 1

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group