When you try to run custom stored procedures that were
generated with the sp_scriptpublicationcustomprocs stored procedure, you receive the following Error 137 message
Must declare the variable '%.*ls'
if all the
following conditions are true:
Immediate-updating subscriptions are permitted on the
publication (@allow_sync_tran = 'True').
Queuing of changes at the subscribers is enabled (@allow_queued_tran = 'True').
The table that has the incorrect custom stored procedures
that were created with the sp_scriptpublicationcustomprocs stored procedure contains computed columns.
The table that has the incorrect custom stored procedures
that were created with the sp_scriptpublicationcustomprocs stored procedure has unique indexes.
To resolve this problem, obtain the latest service pack for Microsoft SQL Server 2000. For additional information, click the following article number to view the article in the Microsoft Knowledge Base:
290211
(http://support.microsoft.com/kb/290211/
)
How to obtain the latest SQL Server 2000 service pack
Follow the steps in the "More Information" section to install and
to activate this fix.
The English version of this fix has the file
attributes (or later) that are listed in the following table. The dates and
times for these files are listed in coordinated universal time (UTC). When you
view the file information, it is converted to local time. To find the
difference between UTC and local time, use the Time Zone tab in the Date and Time tool in Control Panel.
Microsoft
has confirmed that this is a problem in the Microsoft products that are listed
in the "Applies to" section of this article. This problem was first corrected in Microsoft SQL Server 2000 Service Pack 4.
To install and activate the fix, follow these steps:
Obtain the fix that is described in the "Resolution"
section of this article.
Apply the fix to the affected publishing instance of SQL
Server 2000.
Mark the affected subscription for reinitialization:
For Push subscriptions:
In Enterprise
Manager, open the Publisher server tree, and then locate the
Replication - Subscriptions node. Right-click the affected
subscription, and then click Reinitialize.
For Pull subscriptions:
In Enterprise
Manager, open the Subscriber server tree, and then locate the
Replication - Subscriptions node. Right-click the affected
subscription, and then click Reinitialize.
Run the Snapshot Agent for the affected
publication.
To reproduce the problem, run the following script in
a server that already has replication configured:
you will receive the following (incorrect) script:
--
-- Transactional replication custom procedures for publication 'TestDatabase' from database 'TestDatabase':
--
----
---- Replication custom procedures for article 'TestTable':
----
if exists (select * from sysobjects where type = 'P' and name = 'sp_MSins_TestTable') drop proc [sp_MSins_TestTable]
go
create procedure [sp_MSins_TestTable] @c1 int,@c2 int,@c3 uniqueidentifier,@c4 int
AS
BEGIN
if not exists (select * from [TestTable]
where ( [col1] = @c1 ) or ( [col4] = @c5 )
)
BEGIN
insert into [TestTable](
[col1], [col2], [msrepl_tran_version], [col4]
)
values (
@c1, @c2, @c3, @c4
)
END
END
go
if exists (select * from sysobjects where type = 'P' and name = 'sp_MSupd_TestTable') drop proc [sp_MSupd_TestTable]
go
create procedure [sp_MSupd_TestTable]
@c1 int,@c2 int,@c3 uniqueidentifier,@c4 int,@c5 int,@c6 int,@c7 uniqueidentifier,@c8 int
as
if not exists (select * from [TestTable]
where ( [col4] = @c9 and @c9 != @c5 )
)
begin
if @c5 = @c1
begin
update [TestTable] set [col2] = @c6,[msrepl_tran_version] = @c7,[col4] = @c8
where [col1] = @c1
and msrepl_tran_version = @c3
end
else
begin
if not exists (select * from [TestTable]
where ( [col1] = @c5 )
)
begin
update [TestTable] set [col1] = @c5,[col2] = @c6,[msrepl_tran_version] = @c7,[col4] = @c8
where [col1] = @c1
and msrepl_tran_version = @c3
end
end
end
go
if exists (select * from sysobjects where type = 'P' and name = 'sp_MSdel_TestTable') drop proc [sp_MSdel_TestTable]
go
create procedure [sp_MSdel_TestTable] @c1 int,@c2 int,@c3 uniqueidentifier,@c4 int
as
delete [TestTable]
where [col1] = @c1
and msrepl_tran_version = @c3
go
Notice that the custom insert stored procedure, sp_MSins_TestTable, references a parameter that is named @c5. @c5 is not declared as a parameter for that procedure, and the custom
update stored procedure sp_MSupd_TestTable references another undefined parameter named @c9.