Home Microsoft SQL Server DigiMailing iRN Contact
    Keyword



sys.sp_MShelp_subscriberside_history

  No additional text.


Syntax


-- Name: sp_MShelp_subscriberside_history

-- Descriptions:

-- Parameters: as defined in create statement

-- Returns: 0 - success
--          1 - Otherwise

-- Security: internal
-- Requires Certificate signature for catalog access

create procedure sys.sp_MShelp_subscriberside_history
(
	@hours int = 0, /* @hours < 0 will return TOP 100, otherwise look back at only @hours */
	@session_type int = 1, /* 1 for succeed/retry sessions, otherwise failure sessions */	
	@publisher sysname = NULL, -- used to read subscriber-side monitoring tables.
	@publisher_db sysname = NULL, -- used to read subscriber-side monitoring tables.
	@publication sysname = NULL -- used to read subscriber-side monitoring tables.
)
as
begin
	set nocount on
	
    declare @min_time datetime
    declare @subid uniqueidentifier

    declare @succeed int
    declare @retry int
    declare @failure int
    declare @max_session_id int

    select @succeed = 2
    select @retry = 5
    select @failure = 6

    select @subid = subid from dbo.sysmergesubscriptions where
		UPPER(subscriber_server) = UPPER(@@servername)
		and db_name = db_name()
		and pubid in
		(select pubid from dbo.sysmergepublications where
			upper (publisher) = upper (@publisher)
			and publisher_db = @publisher_db
			and name = @publication
			)

    select top 1 @max_session_id = session_id from dbo.MSmerge_sessions with (NOLOCK)
		where subid = @subid
		order by session_id desc

    IF @hours < 0
	BEGIN
    	select top 100
		sessions.session_id as Session_id,
		isnull(sessions.runstatus,0) as Status,
		sessions.start_time as StartTime,
		sessions.end_time as EndTime,
		sessions.duration as Duration,
		sys.fn_replmerge_get_cmdcounts(sessions.session_id, 1) as UploadedCommands,
		sys.fn_replmerge_get_cmdcounts(sessions.session_id, 2) as DownloadedCommands,
		sys.fn_replmerge_get_errormsgcounts(sessions.session_id) as ErrorMessages,
		(
			select top 1 re.id from dbo.MSrepl_errors re
			where re.session_id = sessions.session_id
			order by re.id desc
		) as ErrorID,
		sessions.percent_complete as PercentageDone,
		sessions.time_remaining as TimeRemaining,
		sessions.current_phase_id as CurrentPhase,
		(
				select top 1 rh.comments from dbo.MSmerge_history rh
				where rh.session_id = sessions.session_id
				order by rh.session_id desc, rh.timestamp desc
		) as LastMessage,
		--IsSpidActive = case when exists (select * from sys.dm_exec_sessions sp where sp.login_time = sessions.spid_login_time
		--										and sp.session_id = sessions.spid) then 1 else 0 end
		IsSpidActive = 1
		from dbo.MSmerge_sessions sessions
		where sessions.subid = @subid
		and sessions.session_id <= @max_session_id
		and
		(
			(
				@session_type = 1 and
          		(
          			sessions.runstatus = @succeed
          			or sessions.runstatus = @retry
					or sessions.session_id = @max_session_id
				)
			)
			or sessions.runstatus = @failure
		)
		order by sessions.start_time desc   	
	END
	ELSE
	BEGIN
		IF @hours = 0
		BEGIN
			select @min_time = NULL
		END
		ELSE
		BEGIN
			select @min_time = dateadd(hour, -@hours, getdate())
		END
		-- phase is ReconcilerMsg.lPhase: UPLOAD_PHASE as 1 and DOWNLOAD_PHASE as 2, schema changes as 3
		-- dbo.MSmerge_articlehistory.phase_id
		select
		sessions.session_id as Session_id,
		isnull(sessions.runstatus,0) as Status,
		sessions.start_time as StartTime,
		sessions.end_time as EndTime,
		sessions.duration as Duration,
		sys.fn_replmerge_get_cmdcounts(sessions.session_id, 1) as UploadedCommands,
		sys.fn_replmerge_get_cmdcounts(sessions.session_id, 2) as DownloadedCommands,
		sys.fn_replmerge_get_errormsgcounts(sessions.session_id) as ErrorMessages,
		(
			select top 1 re.id from dbo.MSrepl_errors re
			where re.session_id = sessions.session_id
			order by re.id desc
		) as ErrorID,
		sessions.percent_complete as PercentageDone,
		sessions.time_remaining as TimeRemaining,
		sessions.current_phase_id as CurrentPhase,
		(
				select top 1 rh.comments from dbo.MSmerge_history rh
				where rh.session_id = sessions.session_id
				order by rh.session_id desc, rh.timestamp desc
		) as LastMessage,
		--IsSpidActive = case when exists (select * from sys.dm_exec_sessions sp where sp.login_time = sessions.spid_login_time
		--										and sp.session_id = sessions.spid) then 1 else 0 end
		IsSpidActive = 1
		from dbo.MSmerge_sessions sessions
		where sessions.subid = @subid
		and sessions.session_id <= @max_session_id
		and
		(
			(
				@session_type = 1 and
          		(
          			sessions.runstatus = @succeed
          			or sessions.runstatus = @retry
					or sessions.session_id = @max_session_id
				)
			)
			or sessions.runstatus = @failure
		)
		and (sessions.end_time >= @min_time or @min_time IS NULL)
		order by sessions.start_time desc
	END
	
	return 0
end

 
Last revision 2008RTM
See also

  sp_replmonitorhelpmergesession (Procedure)
       



News

  Query a named instance
Sybase+ASE+silent+install
SQL 2008 R2
Deprecated procedures in SQL2008
Reporting Services item-level role definitions
Create all your missing indexes
Converting datetime field
Start MSSQL Server Profiler at time
Replicating MSSQL Server views
Exploring Microsoft Sharepoint
The OLE DB provider "SQLNCLI10" for linked server indicates.
Mobile solar charger
Oracle to SQL Server replication
Cannot insert the value NULL into column
Undocumented Microsoft SQL Server 2008
VMware
Zoekmachine optimalisatie
SQL Servers hidden objects
FckEditor
Flash in Ajax
De hype die AJAX heet
Barcode scannen
MySQL; Gratis, makkelijk en snel!
PHP
sIFR; de combinatie tussen HTML en Flash