什么是Azure中的Web.Config连接字符串和ServiceConfiguration连接字符串之间的关系? [英] What is the relationship between Web.Config connection strings and ServiceConfiguration connection strings in Azure?

查看:154
本文介绍了什么是Azure中的Web.Config连接字符串和ServiceConfiguration连接字符串之间的关系?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是比较新的Windows Azure的,我需要得到的Azure平台如何处理连接字符串的配置设置一个更好的AP preciation。

I'm relatively new to Windows Azure and I need to get a better appreciation of how the Azure platform handles connection string configuration settings.

假设我有一个ASP.Net Web项目,这有一个web.config连接字符串设置这样的:

Assume I have an ASP.Net web project and this has a Web.Config connection string setting like the following:

    <add name="MyDb" connectionString="Data Source=NzSqlServer01;Initial Catalog=MyAzureDb;User ID=joe;Password=bloggs;"
  providerName="System.Data.SqlClient" />

我使用的本地测试和这样的此连接字符串。假设我有一个的 ServiceConfiguration.Local.cscfg 的文件,该文件认为,相同的连接信息。

I use this connection string for local testing and such. Let's assume I have a ServiceConfiguration.Local.cscfg file that holds that same connection information.

现在我已经准备好部署到Azure的我的实例。我ServiceConfiguration.Cloud.cscfg文件看起来像这样:

Now I'm ready to deploy out to my Azure instance. My ServiceConfiguration.Cloud.cscfg file looks like this:

  <Setting name="MyDb" 
    value="Data Source=tcp:e54wn1clij.database.windows.net;Database=MyAzureDb{0};User ID=joe.bloggs@e54wn1clij;Password=reallysecure;Trusted_Connection=False;Encrypt=True;" />

我试图左右我的头是,如果我在我的web应用程序code,它在寻找所谓的MYDB的连接字符串(例如,通过调用该行code的: ConfigurationManager.ConnectionStrings [CeraDb]。的ConnectionString ),并自动地天青知道基础上,ServiceConfiguration文件的连接字符串查找数据库名为MyAzureDb1或MyAzureDb2,或将在网上应用程序的code简单地寻找在Web.Config中任何的和无法正确平衡负载的数据库连接?

What I'm trying to get my head around is that if I have code in my web application that's looking for a connection string called "MyDb" (for example, by calling this line of code: ConfigurationManager.ConnectionStrings["CeraDb"].ConnectionString), does Azure automagically know to look for a database called MyAzureDb1 or MyAzureDb2 based on the ServiceConfiguration file's connection string, or will the web application's code simply look for whatever's in Web.Config and fail to correctly load-balance the database connections?

推荐答案

本质,除非你code,否则的所有的Azure实例都是一样的的。在你的情况下,这意味着,对于相同的Web角色的两个或更多个实例的配置将是相同的。

Intrinsically, unless you code otherwise, all Azure instances are created equal. In your case, this means that the configuration for two or more instances of the same Web Role will be the same.

所以,如果你已经分片的数据库,并希望不同的情况下阅读不同的数据库,你需要让你的启动code聪明,创造的东​​西,分配到碎片的实例。你已经获得 System.Environment.MachineName 可一旦他们开始实例之间在code区分开来。

So, if you've sharded your database and want different instances to read different databases, you'll need to get clever in your startup code and create something that allocates a shard to an instance. You've access to System.Environment.MachineName which can distinguish in code between instances once they're started.

有几个方法可以做到这一点。其中一个可能是在(比如说)表存储,保持一个日志的碎片实例的最后一个见过一次中央登记。服务器上的后台进程周期性地写入到该日志中。然后,在实例开始,检查最后看到时间为每个碎片 - 如果有的话是陈旧(比当前时间显著老年人较少的写入间隔)则实例知道它可以声称碎片本身作为旧实例已经死了。

There's a few ways to do this. One might be to have a central registry in (say) table storage that keeps a log of the last-seen-time of an instance for a shard. A background process on the server periodically writes out to this log. Then, on instance start, check the last-seen-time for each shard -- if any are "stale" (significantly older than the current time less the write interval) then the instance knows it can claim that shard for itself as the old instance has died.

(,有更好的方法来分片,但一般在系统使用中的数据 - 在你的系统中最大的表例如)

(There are better ways to shard, however, generally around the data your system uses -- e.g. by the largest table in your system.)

这篇关于什么是Azure中的Web.Config连接字符串和ServiceConfiguration连接字符串之间的关系?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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