Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to change connection string on cloud service deploy-time?

I wrote an asp.net mvc 4 web site. For my corporation purpose, I created several publish profiles, in order to publish it on differents azure websites. Each profile changes the connection strings.

It worked very well.

I am now trying to do the same thing with an azure cloud service (I added my web site as a web role in a new cloud service project). But I can't find out how to change the connection string of my web role depending of my cloud service project publish profile at deploy-time.

Is there a way to do such a thing ?

Thanks !

like image 481
fharreau Avatar asked Dec 06 '25 03:12

fharreau


1 Answers

You could store the connection string in the ServiceConfiguration file .cscfg of your Role and then use the following in your code to retrieve the setting:

string connectionString = RoleEnvironment.GetConfigurationSettingValue("myConnectionString");

You can modify the values in the ServiceConfiguration through the Management Portal once deployed.

like image 60
QFDev Avatar answered Dec 09 '25 01:12

QFDev



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!