使用镜像数据库创建 .NET MVC Web 应用程序以实现 HA

发布于 2024-10-22 03:00:48 字数 512 浏览 2 评论 0原文

我正在编写我的第一个 .NET MVC 应用程序,并且使用代码优先方法。我最近学习了如何使用 镜像数据库和见证人(不要与故障转移集群)来执行故障转移过程。我认为现在是将我的 Web 应用程序安装到高可用数据库中来练习这两件事的好时机。

现在,根据我在镜像配置中学到的知识(如果我错了,请纠正我),如果第一个数据库出现故障,您可以将见证故障转移到辅助数据库...但是您的应用程序还需要更改连接字符串以引用辅助服务器。

在 Web.config(或其他地方)中包含两个地址并选择正确的连接字符串的最佳方法是什么?

I am writing my first .NET MVC application and I am using the Code-First approach. I have recently learned how to configure two SQL Servers installations for High Availability using a Mirror Database and a Witness (not to be confused with Failover Clusters) to do the failover process. I think this would be a great time to practice both things by mounting my web app into a highly-available DB.

Now, for what I learned (correct me if I'm wrong) in the mirror configuration you have the witness failover to the secondary DB if the first one goes down... but your application will also need to change the connection string to reference the secondary server.

What is the best approach to have both addresses in the Web.config (or somewhere else) and choosing the right connection string?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

深者入戏 2024-10-29 03:00:48

我对连接镜像数据库的经验为零,所以这都是异端邪说! :)

缺点可能是您可能不需要做任何特殊的事情,只要您在连接字符串中传递 FailoverPartner 属性即可。长此以往,您可能需要额外的错误处理来尝试新连接,因此数据提供实际上将在新连接中使用FailoverPartner名称。

连接客户端似乎有一些不错的信息到数据库镜像会话即可开始。你有机会检查一下吗?

如果没有,则通过 建立初始连接 他们引入了 ConnectionString 属性属性。

重新连接到数据库镜像会话建议在任何客户端由于故障转移而断开连接时,客户端将需要捕获此异常并准备重新连接:

应用程序必须意识到
错误。那么,应用程序需要
关闭失败的连接并
使用相同的方式打开一个新连接
连接字符串属性。

如果FailoverPartner属性可用,则此过程对于客户端来说应该相对透明。

如果上述方法不起作用,那么您可能需要在应用程序层实际引入一些逻辑来跟踪谁是主节点、故障转移节点以及每个节点的连接字符串,并准备好将该信息保留在某处 - 就像数据访问提供商应该为我们做(睁大眼睛)。

还有这篇关于 Sql Server 的数据库镜像的 ServerFault 帖子可能会从具有附加参考信息的操作角度来看是有趣的。

希望有实际经验的人能够支持这一点!

I have zero experience with connecting to Mirrored databases, so this is all heresy! :)

The short of it may be you may not have to do anything special, as long as you pass along the FailoverPartner attribute in your connection string. The long of it is you may need additional error handling to attempt a new connection so the data provide will actually use the FailoverPartner name in the new connection.

There seems to be some good information with Connecting Clients to a Database Mirroring Session to get started. Have you had a chance to check that out?

If not, its there with Making the Initial Connection where they introduce the FailoverPartner attribute of the ConnectionString property attributes.

Reconnecting to a Database Mirroring Session suggests that on any client disconnect due to failover, the client will need to trap this exception and be prepared to reconnect:

The application must become aware of
the error. Then, the application needs
to close the failed connection and
open a new connection using the same
connection string attributes
.

If the FailoverPartner attribute is available, this process should be relatively transparent to the client.

If the above doesn't work, then you might need to actually introduce some logic at the application tier to track who is the primary node, the failover node, and connection strings for each, and be prepared to persist that information somewhere - much like the data access provider should be doing for us (eyes wide open).

There is also this ServerFault post on database mirroring with Sql Server that might be of interest from an operational viewpoint that has additional reference information.

Hopefully someone with actual experience will back up any of this!

谎言 2024-10-29 03:00:48

这可能完全不对劲,但如果您的 Web 服务器和数据库服务器之间有一个负载均衡器会怎么样?

负载均衡器将使用基本的运行状况检查技术(例如 ping 等)在其池中拥有两个数据库。

然后,您的配置只需指向负载均衡器的 IP,无需更改。

这就是这些网络设备的优点。编程框架 (ASP.NET) 的工作不是对服务器的运行状况做出决策。

This may be totally off base, but what if you had a load balancer between your web server and the database servers?

The Load Balancer would have both databases in it's pool, using basic health check techniques (e.g ping, etc).

Your configuration would then only need to point to the IP of the Load Balancer, and wouldn't need to change.

This is what these network devices are good for. It's not the job of the programming framework (ASP.NET) to make decisions on the health of servers.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文