Have to set the Database connection string in the .cscfg file, not the app.config (In my windows azure worker role application). Can anyone help me on this..?
Thanks in Adavance. Cheers.
If you're thinking about setting the connection string in <connectionStrings></connectionStrings>
element in .cscfg
file, you can't do that. Configuration file only takes name/value pair. So you would do something like:
<?xml version="1.0"?>
<ServiceConfiguration serviceName="Web.Azure" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceConfiguration" osFamily="3" osVersion="*" schemaVersion="2013-03.2.0">
<Role name="Worker">
<Instances count="2" />
<ConfigurationSettings>
<Setting name="DatabaseConnectionString" value="your database connection string" />
</ConfigurationSettings>
</Role>
</ServiceConfiguration>
and then read the connection string in your code like:
var databaseConnectionString = RoleEnvironment.GetConfigurationSettingValue("DatabaseConnectionString")
and use that connection string for your database calls.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.