C# 检查数据库镜像状态

发布于 2024-10-01 06:58:32 字数 183 浏览 0 评论 0原文

我们的 C# 应用程序需要连接到 SQL 2005 和 2008 数据库并检查数据库镜像的当前状态(例如是否启用、挂起、暂停、断开连接等)。有哪些属性可以让我检查这一点?

我们所有正在镜像的数据库都没有见证和手动故障转移(同步镜像)。

如果有人可以帮助我或向我指出一些文档,我将非常感激,谷歌搜索并没有在这方面出现太多。

Our C# application needs to connect to SQL 2005 and 2008 databases and check what the current status of database mirroring is (eg. is it enabled, suspended, paused, disconnected etc). Are there properties where I can check this?

All our databases that are being mirrored have no witness and manual failover (synchronous mirroring).

Much appreciated if anyone can help out or point me to some documentation, google searches are not turning up much on this.

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

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

发布评论

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

评论(2

十年不长 2024-10-08 06:58:32

当前状态显示在 sys.database_mirroring 中:

SELECT mirroring_state 
FROM sys.database_mirroring
WHERE database_id = DB_ID('...');

Current state is shown in sys.database_mirroring:

SELECT mirroring_state 
FROM sys.database_mirroring
WHERE database_id = DB_ID('...');
被翻牌 2024-10-08 06:58:32

此处的 MSDN 文章 描述了所有系统存储过程,这些过程将为您提供您需要的信息

您还可以检索或更新
通过运行当前状态
sp_dbmmonitorresults 系统存储
程序。

Remus 的回答中使用 sp_dbmmonitorresults 和使用 sys.database_mirroring 表之间的一个不明显的区别是所需的权限

sys.database_mirroring 所需的权限

根据 MSDN 文章 Remus 引用

查看其他数据库的行
与 master 或 tempdb 相比,您必须
是数据库所有者或至少拥有
更改任何数据库或查看任何
数据库服务器级别权限或
CREATE DATABASE 权限
主数据库。查看非NULL
镜像数据库上的值,您必须
成为系统管理员固定成员
服务器角色

sp_dbmmonitorresults 所需的权限

根据前面提到的关于镜像的 MSDN 文章 SP的

系统管理员固定服务器的成员
角色以及已添加的用户
dbm_monitor 固定数据库角色

The MSDN Article here describes all the System Stored procedures that will give you the information you need

You can also retrieve or update the
current status by running the
sp_dbmmonitorresults system stored
procedure.

One non-obvious difference between using the sp_dbmmonitorresults and using sys.database_mirroring table that's in Remus's answer is the permissions required

Rights needed for sys.database_mirroring

According to the MSDN article Remus referenced

To see the row for a database other
than master or tempdb, you must either
be the database owner or have at least
ALTER ANY DATABASE or VIEW ANY
DATABASE server-level permission or
CREATE DATABASE permission in the
master database. To see non-NULL
values on a mirror database, you must
be a member of the sysadmin fixed
server role

Rights needed for sp_dbmmonitorresults

According to the previous mentioned MSDN article on mirroring SP's

members of the sysadmin fixed server
role, and users who have been added to
the dbm_monitor fixed database role

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