Azure的连接字符串的最佳实践 [英] Azure connection string best practices

查看:204
本文介绍了Azure的连接字符串的最佳实践的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我只是迁移到Azure的应用程序。目前我使用的web.config改造,管理不断变化的连接字符串开发/分期/生产环境数据库。它是如何最好地在Azure中管理多个连接字符串?

I have an application that I am just migrating to Azure. Currently I use web.config transformation to manage changing the database connecting string dev/staging/prod environments. How is it best to manage these multiple connection strings in Azure?

推荐答案

在情况下,它并不重要,如果开发者能够看到生产凭据,您可以使用内置在Visual Studio 10的配置转换。如果这是你在找什么,请按照下列步骤操作:

In cases where it doesn't matter if the developer can see production credentials, you can use the built-in Visual Studio 10 config transformations. If this is what you're looking for, follow these steps:

1.Navigate在文件浏览器搜索您的Azure项目文件夹
2. ServiceConfiguration.cscfg结果的副本
3.重命名副本ServiceConfiguration.Base.cscfg结果
4.对于每个生成配置(例如开发,运行,生产),创建一个ServiceConfiguration<建立配置名称> .cscfg文件。在这些文件中,你可以使用正常的配置转型语法结果
5.在文本编辑器中打开文件.ccproj结果
6.找到以下节点,

1.Navigate to your Azure project folder in file explorer
2. Make a copy of ServiceConfiguration.cscfg
3. Rename copy to ServiceConfiguration.Base.cscfg
4. For each build configuration (e.g. Dev, Staging, Production), create a ServiceConfiguration.<build config name>.cscfg file. In these files, you can use the normal config transformation syntax
5. Open your .ccproj file in a text editor
6. Find the following node,

<ItemGroup>
    <ServiceDefinition Include="ServiceDefinition.csdef" />
    <ServiceConfiguration Include="ServiceConfiguration.cscfg" />
</ItemGroup>

和本替换它(你必须编辑这个区块,以配合您的构建CONFIGS):

and replace it with this (you will have to edit this block to match your build configs):

<ItemGroup>
    <ServiceDefinition Include="ServiceDefinition.csdef" />
    <ServiceConfiguration Include="ServiceConfiguration.cscfg" />
    <None Include="ServiceConfiguration.Base.cscfg">
        <DependentUpon>ServiceConfiguration.cscfg</DependentUpon>
    </None>
    <None Include="ServiceConfiguration.Dev.cscfg">
        <DependentUpon>ServiceConfiguration.cscfg</DependentUpon>
    </None>
    <None Include="ServiceConfiguration.Staging.cscfg">
        <DependentUpon>ServiceConfiguration.cscfg</DependentUpon>
    </None>
    <None Include="ServiceConfiguration.Production.cscfg">
        <DependentUpon>ServiceConfiguration.cscfg</DependentUpon>
    </None>
</ItemGroup>

7.Add在.ccproj文件的末尾以下,略高于&LT; /项目&GT;

<Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.targets" />
<Target Name="BeforeBuild">
    <TransformXml Source="ServiceConfiguration.Base.cscfg" Transform="ServiceConfiguration.$(Configuration).cscfg" Destination="ServiceConfiguration.cscfg" />
</Target>

8.如果你正在使用Visual Studio 10安装没有一个CI服务器,你可能必须复制到C:\\ Program Files文件\\的MSBuild \\微软\\ VisualStudio的\\ 10.0 \\ Web文件夹和其内容从开发计算机到服务器。

8.If you're using a CI server that doesn't have Visual Studio 10 installed, you'll probably have to copy the C:\Program Files\MSBuild\Microsoft\VisualStudio\v10.0\Web folder and its contents from a development machine to the server.

更新:作为@SolarSteve <一个href=\"http://stackoverflow.com/questions/4190984/azure-connection-string-best-practices/6187519#6187519\">noted,你可能有一个命名空间添加到您的ServiceConfiguration。*。cscfg文件。下面是ServiceConfiguration.Base.cscfg的例子:

Update: As @SolarSteve noted, you might have to add a namespace to your ServiceConfiguration.*.cscfg files. Here's an example of ServiceConfiguration.Base.cscfg:

<sc:ServiceConfiguration serviceName="MyServiceName" osFamily="1" osVersion="*" xmlns:sc="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceConfiguration" xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
  <sc:Role name="MyRoleName">
    <sc:Instances count="1" />
    <sc:ConfigurationSettings>
      <sc:Setting name="DataConnectionString" value="xxx" />
    </sc:ConfigurationSettings>
  </sc:Role>
</sc:ServiceConfiguration>

这篇关于Azure的连接字符串的最佳实践的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆