Reputation: 17530
We are hosting 3party sites in our webrole and to limit them access to the storage container I need to set the connection string from code instead of the connection string in serviceconfiguration?
Is this possible?
Based on answer i ran into a problem.
DiagnosticMonitorConfiguration dmConfig = DiagnosticMonitor.GetDefaultInitialConfiguration();
DiagnosticMonitor.StartWithConnectionString(conn, dmConfig);
This resets the configuration to defaults and overrides the stuff that was deployed with the cloud service. I assume when using the StartWithConnectionString, you cant use the support they added in visual studio for setting these things.
Upvotes: 1
Views: 777
Reputation: 136206
Yes, I think you can. Do take a look at DiagnosticMonitor.StartWithConnectionString
method. You would do something like this in your WebRole's OnStart()
method:
DiagnosticMonitorConfiguration dmConfig = DiagnosticMonitor.GetDefaultInitialConfiguration();
DiagnosticMonitor.StartWithConnectionString("DefaultEndpointsProtocol=https;AccountName=accountname;AccountKey=accountkey", dmConfig);
return base.OnStart();
However I would not recommend hard coding the connection string in the code itself. Instead take it from some database.
Upvotes: 3