SQL Server 2022 RMO合并拉取复制Web同步报“不支持该接口”错误
SQL Server 2022合并拉取复制Web同步接口错误排查
环境与问题描述
- 发布/分发服务器同机部署,另有IIS服务器供客户端连接
- 客户端为SQL Server 2022 Express,所有SQL Server版本均为v16.0.4003
- 客户端用RMO库开发的应用处理同步,配置Web Sync时抛出错误:
0x80004002: No such interface supported.
- 移除Web Sync配置后同步正常;用
replmerg控制台应用可正常Web同步,排除服务器配置问题 - 代码中错误捕获仅得到上述提示,
Agent.Output为空,agent.ComErrorCollection无内容
相关代码片段
ServerConnection conn = new Microsoft.SqlServer.Management.Common.ServerConnection(settings.SubscriberName); MergePullSubscription subscription = new MergePullSubscription(); MergeSynchronizationAgent agent; conn.Connect(); subscription.ConnectionContext = conn; subscription.DatabaseName = settings.LocalDBName; subscription.PublisherName = settings.PublisherName; subscription.PublicationDBName = settings.PublicationDBName; subscription.PublicationName = settings.PublicationName; if (subscription.LoadProperties()) { agent = subscription.SynchronizationAgent; agent.Distributor = settings.PublisherName; agent.DistributorSecurityMode = Microsoft.SqlServer.Replication.SecurityMode.Integrated; agent.PublisherSecurityMode = Microsoft.SqlServer.Replication.SecurityMode.Integrated; agent.HostName = Environment.MachineName; agent.SubscriptionType = SubscriptionOption.Pull; agent.ExchangeType = MergeExchangeType.Bidirectional; agent.DownloadGenerationsPerBatch = 200; agent.UploadGenerationsPerBatch = 200; agent.InternetTimeout = settings.TimeoutSeconds; agent.OutputVerboseLevel = 2; agent.UseWebSynchronization = true; agent.InternetSecurityMode = SecurityMode.Standard; agent.InternetUrl = settings.ReplicationURL; agent.InternetLogin = settings.ReplicationUsername; agent.InternetPassword = settings.ReplicationPassword; try { agent.Synchronize(); } catch (Exception ex) { foreach (ComErrorRecord comError in agent.ComErrorCollection) { log.Debug($"Com Error: {comError.ErrorNumber}: {comError.Description}"); } log.Debug("Agent Output: " + agent.Output); log.Error("Error in Syncronize (" + settings.SubscriberName + "): " + ex.Message); EmailLog.Error("Error in Syncronize (" + settings.SubscriberName + "): " + ex.Message); } }
排查与解决思路
- 检查RMO库版本匹配性:确保项目引用的
Microsoft.SqlServer.Rmo和Microsoft.SqlServer.Replication库版本与SQL Server 2022(v16.x)完全一致,直接从SQL Server 2022安装目录(默认C:\Program Files\Microsoft SQL Server\160\SDK\Assemblies)引用程序集,避免版本不兼容导致接口调用失败。 - 验证应用运行位数:SQL Server 2022默认是64位,若客户端应用编译为32位,会导致COM接口位数不兼容。将项目编译目标平台改为x64,确保和SQL Server组件位数一致。
- 手动实例化同步代理:尝试不通过
subscription.SynchronizationAgent获取代理,直接实例化MergeSynchronizationAgent并手动配置所有参数,包括Web同步属性。部分场景下,通过订阅获取的代理可能缺少Web同步所需的COM接口初始化。示例代码:MergeSynchronizationAgent agent = new MergeSynchronizationAgent(); agent.Subscriber = settings.SubscriberName; agent.SubscriberDatabase = settings.LocalDBName; agent.Publisher = settings.PublisherName; agent.PublisherDatabase = settings.PublicationDBName; agent.Publication = settings.PublicationName; // 其余参数(含Web同步配置)按原代码设置 - 重新注册Web同步COM组件:打开管理员命令提示符(64位),执行以下命令重新注册核心组件:
regsvr32 "C:\Program Files\Microsoft SQL Server\160\COM\replrec.dll" regsvr32 "C:\Program Files\Microsoft SQL Server\160\COM\replprov.dll" - 强制生成详细同步日志:指定日志文件路径,强制生成详细日志排查问题:
agent.Output = @"C:\temp\repl_sync_log.txt";
内容的提问来源于stack exchange,提问作者Ben
相关产品推荐
相关产品推荐

