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..?
必须在.cscfg文件中设置数据库连接字符串,而不是app.config(在我的windows azure worker角色应用程序中)。谁可以帮我这个事..?
Thanks in Adavance. Cheers.
谢谢Adavance。干杯。
1 个解决方案
#1
3
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:
如果您正在考虑在.cscfg文件中的
<?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.
并使用该连接字符串进行数据库调用。
#1
3
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:
如果您正在考虑在.cscfg文件中的
<?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.
并使用该连接字符串进行数据库调用。