Error and Symptom:
------------------------------
We got the below detailed error message in the profiler trace.
exec sp_MSadd_repl_error 3109,0,5,N'USER-PC\SQLEXPSP1',N'8114',N'Error converting data type varchar to geometry.',50,1,N'
SQL Merge Agent encountered an error.
This error occurs on the subscriber side (SQLEXPSP1), while the merge agent is applying the changes to the subscription. The data type in the published article is geometry, but it seems to be converted to "varchar" by some unknown reason. And then, conversion error occurs when the merge agent wants to convert the "varchar" back to "geometry" to match the schema on the subscriber.
Reproduce and Analysis:
-----------------------------------------
1. Repro: I spent quite some time to reproduce the same error in my local labs. This error can be always reproduced in SQL Server 2008 and 2008 R2. Below is the error that is captured from the subscriber profiler trace. (You could also capture a similar trace if you run profiler against the SQLEXPSP1 instance.)
exec [dbo].[MSmerge_ins_sp_8F98318B5A5D4AD92A55CAA41E884BDE]
'7E976B77-94C4-DF11-9867-000FFEE4266F',
2,
0x881E2A55A4CA01000000FF,
0x00,
2005,
'', ----this is the null char
'7E976B77-94C4-DF11-9867-000FFEE4266F',
0,
0x00,
90
2. Cause: This SP failed with error "Error converting data type varchar to geometry." The error occurs because this procedure get a null char for the 6th input parameter, which couldn't be converted to a geometry value. By definition, this SP expects a geometry data here.
3. Conclusion: I involved our production team for further clarification. And they confirmed this is a known issue in current builds of SQL Server 2008 SP1 and 2008R2. This is intended to be fixed in next Service Pack release.
Workaround:
------------------------
To work around this issue, we can use the below modified script to manually create the articles with two modified parameters.
exec sp_addmergearticle @publication = N'GeoMetryPub', @article = N'SpatialTable', @source_owner = N'dbo', @source_object = N'SpatialTable', @type = N'table', @description = N'', @creation_script = N'', @pre_creation_cmd = N'drop', @schema_option = 0x000000000C034FD1, @identityrangemanagementoption = N'auto', @pub_identity_range = 10000, @identity_range = 1000, @threshold = 80, @destination_owner = N'dbo', @force_reinit_subscription = 1, @column_tracking = N'false', @subset_filterclause = N'', @vertical_partition = N'false', @verify_resolver_signature = 1, @allow_interactive_resolver = N'false', @fast_multicol_updateproc = N'true', @check_permissions = 0, @subscriber_upload_options = 0, @delete_tracking = N'true', @compensate_for_errors = N'false', @stream_blob_columns = N'false', @partition_options = 0
The @schema_option was 0x000000010C034FD1, and we changed it to 0x000000000C034FD1.
The @stream_blob_columns was N'true' and we changed it to N'false'.
Note: You may need export the articles' creation script before dropping it. Then modify the schema_option and stream_blob_columns parameters, execute it. Then re-sync the replication. It should work after the modification.
Enjoy :) :) and thanks to Microsoft for their excellent support here.