5

SQL Serverフェールオーバークラスター内のどのノードがアクティブノードであるかをプログラムで判断する方法はありますか?または、少なくとも現在のマシンがアクティブノードであるかどうかを判断しますか?

フェールオーバークラスター内の両方の物理ノードで実行されるWindowsプログラムがありますが、アクティブノードで実行されているかどうかによって動作が異なるはずです。その理由の一部は、このプログラムが非アクティブノードとアクティブノードで同時に実行されるべきではないということです。

(プログラムクラスターを認識させることについて少し読んだことがありますが、この単純なシナリオではそれは非常にやり過ぎのようです。)

4

2 に答える 2

9

SQL Serverから:

Select ServerProperty('ComputerNamePhysicalNetBIOS')

ここに示すように、Microsoft.SqlServer.Management.Smo名前空間を介してアクセスすることもできます。

于 2010-12-20T16:12:54.210 に答える
0

あなたはそのようにチェックすることができます:

1.可用性グループのステータスを確認します。

if (select
        ars.role_desc
    from sys.dm_hadr_availability_replica_states ars
    inner join sys.availability_groups ag
    on ars.group_id = ag.group_id
    where ag.name = 'AvailabilityGroupName'
    and ars.is_local = 1) = 'PRIMARY'
begin
    -- this server is the primary replica, do something here
end
else
begin
    -- this server is not the primary replica, (optional) do something here
end

*AvailabilityGroupNameを変更することを忘れないでください

また

2.セカンダリでジョブを実行しないようにします。

IF master.dbo.svf_AgReplicaState('AvailabilityGroupName')=0  raiserror ('This is not the primary replica.',2,1) 

また

3.セカンダリでの書き込みの可用性を確認します。

IF (SELECT CONVERT(sysname,DatabasePropertyEx(DB_NAME(),'Updateability'))) != 'READ_ONLY'
BEGIN

-- this server is the primary replica, do something here

END 

また

4. SQL2014以降の場合:

IF master.dbo.fn_hadr_database_is_primary_replica('Admin') = 1
    BEGIN 
        -- this server is the primary replica, do something here
    END
ELSE 
    BEGIN 
        -- this server is not the primary replica, (optional) do something here
    END 
于 2018-12-13T10:23:56.040 に答える