Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ssl/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql server 2008 使用RMO的SQL Server Express 2008合并复制原因“;执行Transact-SQL语句或批处理时发生异常;错误?_Sql Server 2008_C# 2.0 - Fatal编程技术网

Sql server 2008 使用RMO的SQL Server Express 2008合并复制原因“;执行Transact-SQL语句或批处理时发生异常;错误?

Sql server 2008 使用RMO的SQL Server Express 2008合并复制原因“;执行Transact-SQL语句或批处理时发生异常;错误?,sql-server-2008,c#-2.0,Sql Server 2008,C# 2.0,我试图创建一个合并复制使用RMO编程,我从! 但是在这条线上 publicationDb.EnabledTransPublishing=true 我收到错误-“执行Transact-SQL语句或批处理时发生异常。” 所以请帮我解决这个问题。 等待你的答案。你现在可能已经有了答案,但对于那些可能会问同样问题的人来说。这是因为您使用的是SQL Server的express版本,并且无法在任何版本的SQL Server express中创建发布者/分发者 代码中的实例不是有效实例,因此引发异常 看

我试图创建一个合并复制使用RMO编程,我从!

但是在这条线上

publicationDb.EnabledTransPublishing=true

我收到错误-“执行Transact-SQL语句或批处理时发生异常。

所以请帮我解决这个问题。


等待你的答案。

你现在可能已经有了答案,但对于那些可能会问同样问题的人来说。这是因为您使用的是SQL Server的express版本,并且无法在任何版本的SQL Server express中创建发布者/分发者

代码中的实例不是有效实例,因此引发异常

看看:

还有那句话

Microsoft SQL Server 2008 Express可以作为所有类型复制的订阅服务器,为使用此版本SQL Server的客户端应用程序分发数据提供了一种方便的方法。在复制拓扑中使用SQL Server Express时,请记住以下注意事项: SQL Server Express不能用作发布服务器或分发服务器。但是,合并复制允许在发布服务器和订阅服务器之间双向复制更改。 大宗报价

        string publisherName = "DataSourceName";
        string publicationName = "AdvWorksSalesOrdersMerge";
        string publicationDbName = "AdventureWorksDW2008R2";
        ReplicationDatabase publicationDb;
        MergePublication publication;
        // Create a connection to the Publisher.
        ServerConnection conn = new ServerConnection(publisherName);
          try
        {
             //Connect to the Publisher.
            conn.Connect();

            // Enable the database for merge publication.               
            publicationDb = new ReplicationDatabase(publicationDbName, conn);
            if (publicationDb.LoadProperties())
            {
                if (!publicationDb.EnabledMergePublishing)
                {
                    publicationDb.EnabledMergePublishing = true;
                }
            }
            else
            {
               //  Do something here if the database does not exist. 
                throw new ApplicationException(String.Format(
                    "The {0} database does not exist on {1}.",
                    publicationDb, publisherName));
            }

            // Set the required properties for the merge publication.
            publication = new MergePublication();
            publication.ConnectionContext = conn;
            publication.Name = publicationName;
            publication.DatabaseName = publicationDbName;

            // Enable precomputed partitions.
            publication.PartitionGroupsOption = PartitionGroupsOption.True;

             //Specify the Windows account under which the Snapshot Agent job runs.
            // This account will be used for the local connection to the 
            // Distributor and all agent connections that use Windows Authentication.

              publication.SnapshotGenerationAgentProcessSecurity.Login = userid;
               publication.SnapshotGenerationAgentProcessSecurity.Password = password;

             //Explicitly set the security mode for the Publisher connection
            // Windows Authentication (the default).
            publication.SnapshotGenerationAgentPublisherSecurity.WindowsAuthentication = true;

             //Enable Subscribers to request snapshot generation and filtering.
            publication.Attributes |= PublicationAttributes.AllowSubscriberInitiatedSnapshot;
            publication.Attributes |= PublicationAttributes.DynamicFilters;

            // Enable pull and push subscriptions.
            publication.Attributes |= PublicationAttributes.AllowPull;
            publication.Attributes |= PublicationAttributes.AllowPush;

            if (!publication.IsExistingObject)
            {
                 //Create the merge publication.
                publication.Create();

                // Create a Snapshot Agent job for the publication.
                publication.CreateSnapshotAgent();
            }
            else
            {
                throw new ApplicationException(String.Format(
                    "The {0} publication already exists.", publicationName));
            }

        }

        catch (Exception ex)
        {
             //Implement custom application error handling here.
            throw new Exception(String.Format("The publication {0} could not be created.", publicationName), ex);

        }
        finally
        {
            conn.Disconnect();
        }