c# - 如何在 .cscfg 文件中设置 Windows azure - 辅助角色的数据库连接字符串..?

标签 c# .net azure azure-worker-roles

必须在 .cscfg 文件中设置数据库连接字符串,而不是在 app.config 中(在我的 Windows Azure 辅助角色应用程序中)。 谁能帮我解决这个问题..?

提前致谢。 干杯。

最佳答案

如果您正在考虑在 <connectionStrings></connectionStrings> 中设置连接字符串.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>

然后读取代码中的连接字符串,例如:

var databaseConnectionString = RoleEnvironment.GetConfigurationSettingValue("DatabaseConnectionString")

并使用该连接字符串进行数据库调用。

关于c# - 如何在 .cscfg 文件中设置 Windows azure - 辅助角色的数据库连接字符串..?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19153034/

相关文章:

c# - 根据时间从对象列表中选择第一个、最后一个、最小值、最大值

c# - NodeType.Certificates 需要什么样的规范?

.net - 什么对象应该从数据访问层返回到业务层一个n层系统

c# - .NET 中的 "US Eastern Standard Time"与 "Eastern Standard Time"

.net - 是否可以从类型/函数定义中重构​​泛型参数约束?

Azure函数表绑定(bind)产生大量日志记录噪音

azure - 通过 `vsce` 创建发布者时,我收到 401

c# - Outlook OpenSharedItem 丢失用户属性

c# - 在 HttpContext.Current.User 中存储扩展的 IIdentity (IPrinciple)

c# - 如何从CMD(Shell)编译测试类和 Entity Framework Model.Designer.cs