Home
%3CLINGO-SUB%20id%3D%22lingo-sub-334000%22%20slang%3D%22en-US%22%3EProcedure%20Execution%20with%20Table-Valued%20Parameters%20Involved%20Cannot%20be%20Replicated%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-334000%22%20slang%3D%22en-US%22%3E%3CP%3E%3CSTRONG%3EFirst%20published%20on%20MSDN%20on%20Apr%2018%2C%202013%20%3C%2FSTRONG%3E%20%3CBR%20%2F%3E%3CBR%20%2F%3E%3CBR%20%2F%3ESomebody%20approached%20me%20with%20this%20error%2C%20asking%20whether%20this%20is%20by%20design%20or%20caused%20by%20certain%20conditions.%3C%2FP%3E%0A%3CBLOCKQUOTE%3EMsg%2025023%2C%20Level%2016%2C%20State%201%2C%20Server%20%3CREMOVED%20name%3D%22%22%3E%2C%20Procedure%20sp_MSaddexecarticle%2C%20Line%20192%20%3CBR%20%2F%3EStored%20procedures%20containing%20table-value%20parameters%20cannot%20be%20published%20as%20'%5Bserializable%5D%20proc%20exec'%20articles.%3C%2FREMOVED%3E%3C%2FBLOCKQUOTE%3E%0A%3CP%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CBR%20%2F%3EStep%201%3A%20The%20first%20thing%20I%20wanted%20to%20do%20was%20to%20attempt%20to%20reproduce%20the%20issue%20and%20see%20if%20this%20happens%20%E2%80%9Cout%20of%20the%20box%E2%80%9D.%20The%20idea%20is%20to%20create%20a%20TVP%20scenario%20and%20then%20use%20transactional%20replication%20to%20replicate%20stored%20procedure%20execution.%3C%2FP%3E%0A%3CBLOCKQUOTE%3EDROP%20TABLE%20tbl_tvptest%20%3CBR%20%2F%3ECREATE%20TABLE%20tbl_tvptest%20(c1%20int%20primary%20key%20nonclustered%2C%20c2%20varchar(2000))%20%3CBR%20%2F%3EINSERT%20INTO%20tbl_tvptest%26nbsp%3B%20VALUE%20(1%2C%20'abc')%20%3CBR%20%2F%3EINSERT%20INTO%20tbl_tvptest%26nbsp%3B%20VALUES%20(2%2C%20'def')%20%3CBR%20%2F%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CBR%20%2F%3EGO%20%3CBR%20%2F%3E%3CBR%20%2F%3ECREATE%20TYPE%20TVP%20AS%20TABLE%20%3CBR%20%2F%3E(%20c1%20int%20%3CBR%20%2F%3E%2C%20c2%20varchar%20(2000))%3B%20%3CBR%20%2F%3EGO%20%3CBR%20%2F%3E%3CBR%20%2F%3E%2F*%20Create%20a%20procedure%20to%20receive%20data%20for%20the%20table-valued%20parameter.%20*%2F%20%3CBR%20%2F%3ECREATE%20PROCEDURE%20dbo.usp_TestTVP%20%3CBR%20%2F%3E%40TVP%20TVP%20READONLY%20%3CBR%20%2F%3EAS%20%3CBR%20%2F%3ESET%20NOCOUNT%20ON%20%3CBR%20%2F%3EINSERT%20INTO%20dbo.TVPTest%20%3CBR%20%2F%3E(c1%2C%20c2)%20%3CBR%20%2F%3ESELECT%20*%20%3CBR%20%2F%3EFROM%26nbsp%3B%20%40TVP%3B%20%3CBR%20%2F%3EGO%20%3CBR%20%2F%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%2F*%20Declare%20a%20variable%20that%20references%20the%20type.%20*%2F%20%3CBR%20%2F%3EDECLARE%20%40TVPvar%20AS%20TVP%3B%20%3CBR%20%2F%3E%3CBR%20%2F%3E%2F*%20Add%20data%20to%20the%20table%20variable.%20*%2F%20%3CBR%20%2F%3EINSERT%20INTO%20%40TVPvar%20%3CBR%20%2F%3ESELECT%203%2C%20'xzy'%20%3CBR%20%2F%3E%3CBR%20%2F%3E%2F*%20Pass%20the%20table%20variable%20data%20to%20a%20stored%20procedure%20to%20test%20it.%20*%2F%20%3CBR%20%2F%3EEXEC%20usp_TestTVP%20%40TVPvar%20%3CBR%20%2F%3EGO%3C%2FBLOCKQUOTE%3E%0A%3CP%3E%3CBR%20%2F%3ENow%2C%20create%20the%20publication%20and%20articles%3C%2FP%3E%0A%3CBLOCKQUOTE%3E--%20Enabling%20the%20replication%20database%20%3CBR%20%2F%3Euse%20master%20%3CBR%20%2F%3Eexec%20sp_replicationdboption%20%40dbname%20%3D%20N'DB1'%2C%20%40optname%20%3D%20N'publish'%2C%20%40value%20%3D%20N'true'%20%3CBR%20%2F%3EGO%20%3CBR%20%2F%3E%3CBR%20%2F%3Eexec%20%5BDB1%5D.sys.sp_addlogreader_agent%20%40job_login%20%3D%20null%2C%20%40job_password%20%3D%20null%2C%20%40publisher_security_mode%20%3D%201%20%3CBR%20%2F%3EGO%20%3CBR%20%2F%3E--%20Adding%20the%20transactional%20publication%20%3CBR%20%2F%3Euse%20%5BDB1%5D%20%3CBR%20%2F%3Eexec%20sp_addpublication%20%40publication%20%3D%20N'TVPTest'%2C%20%40description%20%3D%20N'Transactional%20publication%20of%20database%20''DB1''%20from%20Publisher%20''myServer%5CSQL2008R2''.'%2C%20%40sync_method%20%3D%20N'concurrent'%2C%20%40retention%20%3D%200%2C%20%40allow_push%20%3D%20N'true'%2C%20%40allow_pull%20%3D%20N'true'%2C%20%40allow_anonymous%20%3D%20N'true'%2C%20%40enabled_for_internet%20%3D%20N'false'%2C%20%40snapshot_in_defaultfolder%20%3D%20N'true'%2C%20%40compress_snapshot%20%3D%20N'false'%2C%20%40ftp_port%20%3D%2021%2C%20%40ftp_login%20%3D%20N'anonymous'%2C%20%40allow_subscription_copy%20%3D%20N'false'%2C%20%40add_to_active_directory%20%3D%20N'false'%2C%20%40repl_freq%20%3D%20N'continuous'%2C%20%40status%20%3D%20N'active'%2C%20%40independent_agent%20%3D%20N'true'%2C%20%40immediate_sync%20%3D%20N'true'%2C%20%40allow_sync_tran%20%3D%20N'false'%2C%20%40autogen_sync_procs%20%3D%20N'false'%2C%20%40allow_queued_tran%20%3D%20N'false'%2C%20%40allow_dts%20%3D%20N'false'%2C%20%40replicate_ddl%20%3D%201%2C%20%40allow_initialize_from_backup%20%3D%20N'false'%2C%20%40enabled_for_p2p%20%3D%20N'false'%2C%20%40enabled_for_het_sub%20%3D%20N'false'%20%3CBR%20%2F%3EGO%20%3CBR%20%2F%3E%3CBR%20%2F%3Eexec%20sp_addpublication_snapshot%20%40publication%20%3D%20N'TVPTest'%2C%20%40frequency_type%20%3D%201%2C%20%40frequency_interval%20%3D%200%2C%20%40frequency_relative_interval%20%3D%200%2C%20%40frequency_recurrence_factor%20%3D%200%2C%20%40frequency_subday%20%3D%200%2C%20%40frequency_subday_interval%20%3D%200%2C%20%40active_start_time_of_day%20%3D%200%2C%20%40active_end_time_of_day%20%3D%20235959%2C%20%40active_start_date%20%3D%200%2C%20%40active_end_date%20%3D%200%2C%20%40job_login%20%3D%20null%2C%20%40job_password%20%3D%20null%2C%20%40publisher_security_mode%20%3D%201%20%3CBR%20%2F%3Eexec%20sp_grant_publication_access%20%40publication%20%3D%20N'TVPTest'%2C%20%40login%20%3D%20N'sa'%20%3CBR%20%2F%3EGO%20%3CBR%20%2F%3Eexec%20sp_grant_publication_access%20%40publication%20%3D%20N'TVPTest'%2C%20%40login%20%3D%20N'NT%20AUTHORITY%5CSYSTEM'%20%3CBR%20%2F%3EGO%20%3CBR%20%2F%3Eexec%20sp_grant_publication_access%20%40publication%20%3D%20N'TVPTest'%2C%20%40login%20%3D%20N'AD%5CJoseph'%20%3CBR%20%2F%3EGO%20%3CBR%20%2F%3Eexec%20sp_grant_publication_access%20%40publication%20%3D%20N'TVPTest'%2C%20%40login%20%3D%20N'NT%20SERVICE%5CMSSQL%24SQL2008R2'%20%3CBR%20%2F%3EGO%20%3CBR%20%2F%3Eexec%20sp_grant_publication_access%20%40publication%20%3D%20N'TVPTest'%2C%20%40login%20%3D%20N'NT%20SERVICE%5CSQLAgent%24SQL2008R2'%20%3CBR%20%2F%3EGO%20%3CBR%20%2F%3Eexec%20sp_grant_publication_access%20%40publication%20%3D%20N'TVPTest'%2C%20%40login%20%3D%20N'distributor_admin'%20%3CBR%20%2F%3EGO%20%3CBR%20%2F%3E%3CBR%20%2F%3E--%20Adding%20the%20transactional%20articles%20%3CBR%20%2F%3Euse%20%5BDB1%5D%20%3CBR%20%2F%3Eexec%20sp_addarticle%20%40publication%20%3D%20N'TVPTest'%2C%20%40article%20%3D%20N'TVPTest'%2C%20%40source_owner%20%3D%20N'dbo'%2C%20%40source_object%20%3D%20N'TVPTest'%2C%20%40type%20%3D%20N'logbased'%2C%20%40description%20%3D%20N''%2C%20%40creation_script%20%3D%20N''%2C%20%40pre_creation_cmd%20%3D%20N'drop'%2C%20%40schema_option%20%3D%200x000000000803509F%2C%20%40identityrangemanagementoption%20%3D%20N'none'%2C%20%40destination_table%20%3D%20N'TVPTest'%2C%20%40destination_owner%20%3D%20N'dbo'%2C%20%40status%20%3D%2024%2C%20%40vertical_partition%20%3D%20N'false'%2C%20%40ins_cmd%20%3D%20N'CALL%20%5Bsp_MSins_dboTVPTest%5D'%2C%20%40del_cmd%20%3D%20N'CALL%20%5Bsp_MSdel_dboTVPTest%5D'%2C%20%40upd_cmd%20%3D%20N'SCALL%20%5Bsp_MSupd_dboTVPTest%5D'%20%3CBR%20%2F%3EGO%20%3CBR%20%2F%3Euse%20%5BDB1%5D%20%3CBR%20%2F%3EGO%20%3CBR%20%2F%3E%3CBR%20%2F%3Eexec%20sp_addarticle%20%3CBR%20%2F%3E%40publication%20%3D%20N'TVPTest'%2C%20%3CBR%20%2F%3E%40article%20%3D%20N'usp_TestTVP'%2C%20%3CBR%20%2F%3E%40source_owner%20%3D%20N'dbo'%2C%20%3CBR%20%2F%3E%40source_object%20%3D%20N'usp_TestTVP'%2C%20%3CBR%20%2F%3E%3CSTRONG%3E%20%40type%20%3D%20N'serializable%20proc%20exec'%2C%20%3C%2FSTRONG%3E%20%E2%80%93%E2%80%93%20tried%20'proc%20exec'%20as%20well%20%3CBR%20%2F%3E%40description%20%3D%20N''%2C%20%3CBR%20%2F%3E%40creation_script%20%3D%20N''%2C%20%3CBR%20%2F%3E%40pre_creation_cmd%20%3D%20N'drop'%2C%20%3CBR%20%2F%3E%40schema_option%20%3D%200x0000000008000001%2C%20%3CBR%20%2F%3E%40destination_table%20%3D%20N'usp_TestTVP'%2C%20%3CBR%20%2F%3E%40destination_owner%20%3D%20N'dbo'%2C%20%3CBR%20%2F%3E%40status%20%3D%2016%20%3CBR%20%2F%3EGO%3C%2FBLOCKQUOTE%3E%0A%3CP%3E%3CBR%20%2F%3ESure%20enough%2C%20I%20received%20the%20error.%20So%20it%20appears%20that%20this%20is%20reproducible%20at%20will%20with%20the%20simplest%20of%20situations.%20%3CBR%20%2F%3E%3CBR%20%2F%3EStep%202%3A%20Next%2C%20I%20took%20a%20look%20at%20the%20source%20code%20of%20sp_MSaddexecarticle.%20I%20found%20the%20following%2C%20which%20pretty%20much%20confirmed%20my%20findings.%3C%2FP%3E%0A%3CBLOCKQUOTE%3EIF%20EXISTS%20(SELECT%20*%20%3CBR%20%2F%3EFROM%20sys.parameters%20%3CBR%20%2F%3EWHERE%20object_id%20%3D%20%40procid%20%3CBR%20%2F%3EAND%20system_type_id%20%3D%20243)%20%3CBR%20%2F%3EBEGIN%20%3CBR%20%2F%3E--%20Stored%20procedures%20containing%20table-value%20parameters%20cannot%20be%20published%20as%20'%5Bserializable%5D%20proc%20exec'%20articles.%20%3CBR%20%2F%3ERAISERROR%20(25023%2C%2016%2C%20-1)%20%3CBR%20%2F%3ERETURN%20(1)%20%3CBR%20%2F%3EEND%3C%2FBLOCKQUOTE%3E%0A%3CP%3E%3CBR%20%2F%3EEssentially%20the%20code%20is%20checking%20if%20one%20of%20the%20stored%20procedure%20parameters%20is%20a%20TVP%20(type%20%3D%20243)%20and%20if%20so%2C%20raises%20the%20error.%20%3CBR%20%2F%3E%3CBR%20%2F%3EConclusion%3A%20TVPs%20are%20not%20supported%20as%20parameters%20for%20stored%20procedures%20the%20execution%20of%20which%20you%20want%20to%20replicate.%20%3CBR%20%2F%3E%3CBR%20%2F%3ENamaste!%20Joseph%20%3CBR%20%2F%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-334000%22%20slang%3D%22en-US%22%3E%3CP%3EFirst%20published%20on%20MSDN%20on%20Apr%2018%2C%202013%20%26nbsp%3BSomebody%20approached%20me%20with%20this%20error%2C%20asking%20whether%20this%20is%20by%20design%20or%20caused%20by%20certain%20conditions.%3C%2FP%3E%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-334000%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3Etroubleshooting%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ETSQL%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Microsoft

First published on MSDN on Apr 18, 2013


Somebody approached me with this error, asking whether this is by design or caused by certain conditions.

Msg 25023, Level 16, State 1, Server <removed name>, Procedure sp_MSaddexecarticle, Line 192
Stored procedures containing table-value parameters cannot be published as '[serializable] proc exec' articles.




Step 1: The first thing I wanted to do was to attempt to reproduce the issue and see if this happens “out of the box”. The idea is to create a TVP scenario and then use transactional replication to replicate stored procedure execution.

DROP TABLE tbl_tvptest
CREATE TABLE tbl_tvptest (c1 int primary key nonclustered, c2 varchar(2000))
INSERT INTO tbl_tvptest  VALUE (1, 'abc')
INSERT INTO tbl_tvptest  VALUES (2, 'def')



GO

CREATE TYPE TVP AS TABLE
( c1 int
, c2 varchar (2000));
GO

/* Create a procedure to receive data for the table-valued parameter. */
CREATE PROCEDURE dbo.usp_TestTVP
@TVP TVP READONLY
AS
SET NOCOUNT ON
INSERT INTO dbo.TVPTest
(c1, c2)
SELECT *
FROM  @TVP;
GO



/* Declare a variable that references the type. */
DECLARE @TVPvar AS TVP;

/* Add data to the table variable. */
INSERT INTO @TVPvar
SELECT 3, 'xzy'

/* Pass the table variable data to a stored procedure to test it. */
EXEC usp_TestTVP @TVPvar
GO


Now, create the publication and articles

-- Enabling the replication database
use master
exec sp_replicationdboption @dbname = N'DB1', @optname = N'publish', @value = N'true'
GO

exec [DB1].sys.sp_addlogreader_agent @job_login = null, @job_password = null, @publisher_security_mode = 1
GO
-- Adding the transactional publication
use [DB1]
exec sp_addpublication @publication = N'TVPTest', @description = N'Transactional publication of database ''DB1'' from Publisher ''myServer\SQL2008R2''.', @sync_method = N'concurrent', @retention = 0, @allow_push = N'true', @allow_pull = N'true', @allow_anonymous = N'true', @enabled_for_internet = N'false', @snapshot_in_defaultfolder = N'true', @compress_snapshot = N'false', @ftp_port = 21, @ftp_login = N'anonymous', @allow_subscription_copy = N'false', @add_to_active_directory = N'false', @repl_freq = N'continuous', @status = N'active', @independent_agent = N'true', @immediate_sync = N'true', @allow_sync_tran = N'false', @autogen_sync_procs = N'false', @allow_queued_tran = N'false', @allow_dts = N'false', @replicate_ddl = 1, @allow_initialize_from_backup = N'false', @enabled_for_p2p = N'false', @enabled_for_het_sub = N'false'
GO

exec sp_addpublication_snapshot @publication = N'TVPTest', @frequency_type = 1, @frequency_interval = 0, @frequency_relative_interval = 0, @frequency_recurrence_factor = 0, @frequency_subday = 0, @frequency_subday_interval = 0, @active_start_time_of_day = 0, @active_end_time_of_day = 235959, @active_start_date = 0, @active_end_date = 0, @job_login = null, @job_password = null, @publisher_security_mode = 1
exec sp_grant_publication_access @publication = N'TVPTest', @login = N'sa'
GO
exec sp_grant_publication_access @publication = N'TVPTest', @login = N'NT AUTHORITY\SYSTEM'
GO
exec sp_grant_publication_access @publication = N'TVPTest', @login = N'AD\Joseph'
GO
exec sp_grant_publication_access @publication = N'TVPTest', @login = N'NT SERVICE\MSSQL$SQL2008R2'
GO
exec sp_grant_publication_access @publication = N'TVPTest', @login = N'NT SERVICE\SQLAgent$SQL2008R2'
GO
exec sp_grant_publication_access @publication = N'TVPTest', @login = N'distributor_admin'
GO

-- Adding the transactional articles
use [DB1]
exec sp_addarticle @publication = N'TVPTest', @article = N'TVPTest', @source_owner = N'dbo', @source_object = N'TVPTest', @type = N'logbased', @description = N'', @creation_script = N'', @pre_creation_cmd = N'drop', @schema_option = 0x000000000803509F, @identityrangemanagementoption = N'none', @destination_table = N'TVPTest', @destination_owner = N'dbo', @status = 24, @vertical_partition = N'false', @ins_cmd = N'CALL [sp_MSins_dboTVPTest]', @del_cmd = N'CALL [sp_MSdel_dboTVPTest]', @upd_cmd = N'SCALL [sp_MSupd_dboTVPTest]'
GO
use [DB1]
GO

exec sp_addarticle
@publication = N'TVPTest',
@article = N'usp_TestTVP',
@source_owner = N'dbo',
@source_object = N'usp_TestTVP',
@type = N'serializable proc exec', –– tried 'proc exec' as well
@description = N'',
@creation_script = N'',
@pre_creation_cmd = N'drop',
@schema_option = 0x0000000008000001,
@destination_table = N'usp_TestTVP',
@destination_owner = N'dbo',
@status = 16
GO


Sure enough, I received the error. So it appears that this is reproducible at will with the simplest of situations.

Step 2: Next, I took a look at the source code of sp_MSaddexecarticle. I found the following, which pretty much confirmed my findings.

IF EXISTS (SELECT *
FROM sys.parameters
WHERE object_id = @procid
AND system_type_id = 243)
BEGIN
-- Stored procedures containing table-value parameters cannot be published as '[serializable] proc exec' articles.
RAISERROR (25023, 16, -1)
RETURN (1)
END


Essentially the code is checking if one of the stored procedure parameters is a TVP (type = 243) and if so, raises the error.

Conclusion: TVPs are not supported as parameters for stored procedures the execution of which you want to replicate.

Namaste!

Joseph