Home Microsoft SQL Server DigiMailing iRN Contact
    Keyword



sys.sp_MSrepl_changelogreader_agent

  No additional text.


Syntax
CREATE PROCEDURE sys.sp_MSrepl_changelogreader_agent
(
	@job_login					nvarchar(257),
	@job_password				sysname,
	@publisher_security_mode	smallint,
	@publisher_login			sysname,
	@publisher_password 		sysname,
	@publisher					sysname,
	@publisher_type 			sysname
)
AS
BEGIN
	SET NOCOUNT ON

	DECLARE @retcode			int,
			@procedure			nvarchar(4000),
			@distributor_rpc	sysname,
			@distribution_db	sysname,
			@publisher_db		sysname,
			@logreader_exists	bit,
			@proxy_id			int
	
	-- Security Check
	EXEC @retcode = sys.sp_MSreplcheck_publish
	IF @@ERROR <> 0 OR @retcode <> 0
		RETURN 1
	
	-- defaults
	SELECT @publisher_db		= DB_NAME(),
			@logreader_exists	= 0

	-- must be tran published
	IF sys.fn_MSrepl_istranpublished(DB_NAME(),1) <> 1
	BEGIN
		RAISERROR (14013, 16, -1)
		RETURN 1
	END

	-- SQLSERVER
	IF @publisher_type = N'MSSQLSERVER'
	BEGIN
		SELECT @publisher = publishingservername()
	
		IF @publisher_security_mode IS NOT NULL
		BEGIN
			IF @publisher_security_mode not in (0, 1)
			BEGIN
				-- The specified '@publisher_security_mode' is invalid (valid values are: 0, 1).
				RAISERROR(14266, 16, -1, '@publisher_security_mode', '0, 1')
				RETURN 1
			END

			-- make sure that the login is valid
			SELECT @publisher_login = RTRIM(LTRIM(ISNULL(@publisher_login, '')))
			IF @publisher_security_mode = 0 AND @publisher_login = ''
			BEGIN
				-- '@publisher_login cannot be null or empty when @publisher_security_mode is set to 0 (SQL Server authentication).'
				RAISERROR(21694, 16, -1, '@publisher_login', '@publisher_security_mode')
				RETURN 1
			END
		END

		IF @job_login IS NOT NULL
		BEGIN
			IF sys.fn_replisvalidwindowsloginformat(@job_login) != 1
			BEGIN
				-- '@job_login' must be a valid Windows Login in the form : 'MACHINE\Login' or 'DOMAIN\Login'. Please see the documentation for 'sp_changelogreader_agent'.
				RAISERROR(21797, 16, -1, '@job_login', 'sp_changelogreader_agent')
				RETURN 1
			END
		END
	END
	-- HETERO
	ELSE
	BEGIN
		IF @publisher_security_mode IS NOT NULL
		BEGIN
			-- The @publisher_security_mode parameter value can not be updated/changed for heterogeneous publications.
			RAISERROR(22536, 16, -1, '@publisher_security_mode')
			RETURN 1
		END

		IF @publisher_login IS NOT NULL
		BEGIN
			-- The @publisher_login parameter value can not be updated/changed for heterogeneous publications.
			RAISERROR(22536, 16, -1, '@publisher_login')
			RETURN 1
		END

		-- It is reasonable to expect that periodically, the password associated with the Oracle replication administrator
		-- will need to be changed.  This allows the logreader agent to be updated to reflect that change. Bug 381331.
		-- IF @publisher_password IS NOT NULL
		-- BEGIN
		--	-- The @publisher_password parameter value can not be updated/changed for heterogeneous publications.
		--	RAISERROR(22536, 16, -1, '@publisher_password')
		--	RETURN 1
		-- END

		/*
		** In this case we will allow @job_login to be changed only if the
		** publisher_security_mode was set to 0 when the distpublisher was
		** configured. Error is raised in sp_MSchange_logreader_agent_properties.
		*/
		-- IF @job_login IS NOT NULL
		-- BEGIN
		-- 	-- The @job_login parameter value can not be updated/changed for heterogeneous publications.
		-- 	RAISERROR(22536, 16, -1, '@job_login')
		-- 	RETURN 1
		-- END
	END

	-- retrieve the distribution database name			
	EXEC @retcode = sys.sp_helpdistributor @rpcsrvname = @distributor_rpc OUTPUT,
											@distribdb = @distribution_db OUTPUT,
											@publisher = @publisher
	IF @@error <> 0 or @retcode <> 0 or @distribution_db is NULL
	BEGIN
		-- "The Distributor has not been installed correctly."
		RAISERROR(20036, 16, -1)
		RETURN 1
	END
			
	SELECT @procedure = QUOTENAME(RTRIM(@distributor_rpc)) + '.' + QUOTENAME(RTRIM(@distribution_db)) + '.sys.sp_MSreplagentjobexists'
	EXEC @retcode = @procedure @type = 2,
								@exists = @logreader_exists OUTPUT,
								@publisher = @publisher,
								@publisher_db = @publisher_db,
								@proxy_id = @proxy_id OUTPUT
	IF @retcode <> 0 OR @@ERROR <> 0
		RETURN 1
	
	-- EXIT if NOT FOUND
	IF @logreader_exists = 0
	BEGIN	
		declare @publishingservername sysname
		set @publishingservername = publishingservername()
		-- "The logreader agent for publisher (%s), database (%s), publication (%s) could not be found."
		RAISERROR(21799, 16, -1, 'logreader', @publishingservername, @publisher_db, 'all')
		RETURN 1
	END

	IF IS_SRVROLEMEMBER('sysadmin') != 1
		AND @proxy_id IS NULL
	BEGIN
		-- Only members of the sysadmin fixed server role can modify a logreader agent that does not have a job with a proxy account defined.
		RAISERROR(20813, 16, -1, 'logreader agent')
		RETURN 1
	END
	
	-- if any parameter was provide then perform the update
	IF @job_login IS NOT NULL
		OR @job_password IS NOT NULL
		OR @publisher_security_mode IS NOT NULL
		OR @publisher_login IS NOT NULL
		OR @publisher_password IS NOT NULL
	BEGIN
		-- Schedule Log Reader agent for the database
		SELECT @procedure = QUOTENAME(RTRIM(@distributor_rpc)) + '.' + QUOTENAME(RTRIM(@distribution_db)) + '.sys.sp_MSchange_logreader_agent_properties'	

		EXEC @retcode = @procedure @publisher = @publisher,
									@publisher_db = @publisher_db,
									@publisher_security_mode = @publisher_security_mode,
									@publisher_login = @publisher_login,
									@publisher_password = @publisher_password,											
									@job_login = @job_login,
									@job_password = @job_password,
									@publisher_type = @publisher_type
		IF @@ERROR <> 0 or @retcode <> 0
			RETURN 1
	END

	RETURN 0
END

 
Last revision 2008RTM
See also

  sp_changelogreader_agent (Procedure)
sp_MSdrop_repltran (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