Beispiel #1
0
    //创建发布
    protected void Button4_Click(object sender, EventArgs e)
    {
        string publisherName     = SMO.publisherName;       // "rd01";//发布者名
        string publicationName   = SMO.publicationName;     // "HdHousePub";//发布名
        string publicationDbName = SMO.publicationDatabase; // "HdHouse";//发布的数据库名
        //创建连接
        ServerConnection    conn = new ServerConnection(publisherName);
        ReplicationDatabase replicationDatabase = new ReplicationDatabase();

        replicationDatabase.Name = publicationDbName;
        replicationDatabase.ConnectionContext = conn;
        if (!replicationDatabase.LoadProperties())
        {
            Label5.Text    = "请确定发布数据库" + publicationDbName + "已存在";
            TextBox3.Text += "请确定发布数据库" + publicationDbName + "已存在  \r\n";
            return;
        }

        if (!replicationDatabase.EnabledMergePublishing)
        {
            replicationDatabase.EnabledMergePublishing = true;
            replicationDatabase.CommitPropertyChanges();
        }

        MergePublication mergePub = new MergePublication();

        mergePub.ConnectionContext = conn;
        mergePub.DatabaseName      = publicationDbName;
        mergePub.Name = publicationName;
        //mergePub.SnapshotGenerationAgentProcessSecurity
        //mergePub.Attributes |= PublicationAttributes.;
        mergePub.Create();
        mergePub.CreateSnapshotAgent();
    }
Beispiel #2
0
    /// <summary>
    /// 处理请求的定阅
    /// </summary>
    /// <param name="subscriberServer">定阅者服务器名</param>
    /// <param name="subscriptionDatabase">定阅者本地数据库名</param>
    /// <returns></returns>
    public bool RegisterSubscriptionOnPublisher(string subscriberServer, string subscriptionDatabase)
    {
        //string subscriptionDatabase = "SHdHouse";//定阅者本地数据库名
        //string subscriberServer = "rd01";//定阅者服务器
        Boolean          isSubKnown = false;
        ServerConnection con        = new ServerConnection(publisherName);
        MergePublication mergePub   = new MergePublication(publicationName,
                                                           publicationDatabase, con);

        // Load publication properties from the Publisher.
        try
        {
            if (!mergePub.LoadProperties())
            {
                throw new ApplicationException(Environment.NewLine);
            }

            // Determine if the subscription is already registered at the Publisher.
            foreach (MergeSubscription regSub in mergePub.EnumSubscriptions())
            {
                if (regSub.DatabaseName == publicationDatabase &&
                    regSub.SubscriptionDBName == subscriptionDatabase &&
                    regSub.SubscriberName == subscriberServer &&
                    regSub.SubscriberType == MergeSubscriberType.Local &&
                    regSub.SubscriptionType == SubscriptionOption.Pull)
                {
                    // Subscription is already registered at the Publisher.
                    isSubKnown = true;
                }
            }

            if (!isSubKnown)
            {
                // Register the new subscription at the Publisher.
                mergePub.MakePullSubscriptionWellKnown(subscriberServer,
                                                       subscriptionDatabase, SubscriptionSyncType.Automatic,
                                                       MergeSubscriberType.Local, 80.0f);
            }
        }
        catch (InvalidCastException ex)
        {
            throw new ApplicationException(ex.ToString());
        }
        return(true);
    }
Beispiel #3
0
    //删除
    protected void Button15_Click(object sender, EventArgs e)
    {
        ServerConnection sconn = new ServerConnection(SMO.publisherName);

        try
        {
            MergePublication mpc = new MergePublication();
            mpc.Name              = SMO.publicationName;
            mpc.DatabaseName      = SMO.publicationDatabase;
            mpc.ConnectionContext = sconn;
            if (mpc.IsExistingObject)
            {
                mpc.Remove();
            }
            else
            {
                TextBox3.Text = "发布" + SMO.publicationName + "的定义不正确,或者发布不存在。\r\n";
            }
            ReplicationDatabase rld = new ReplicationDatabase();
            rld.ConnectionContext = sconn;
            rld.Name = SMO.publicationName;
            if (rld.LoadProperties())
            {
                rld.EnabledMergePublishing = false;
                rld.CommitPropertyChanges();
            }
            else
            {
                TextBox3.Text = "请验证" + SMO.publicationDatabase + "数据库是否存在。\r\n";
            }
        }
        catch (Exception ex)
        {
            throw new ApplicationException(String.Format(
                                               "The publication {0} 无法删除.", SMO.publicationName), ex);
        }
        finally
        {
            sconn.Disconnect();
        }
    }
Beispiel #4
0
    /// <summary>
    /// 处理请求的定阅
    /// </summary>
    /// <param name="subscriberServer">定阅者服务器名</param>
    /// <param name="subscriptionDatabase">定阅者本地数据库名</param>
    /// <returns></returns>
    public bool RegisterSubscriptionOnPublisher(string subscriberServer, string subscriptionDatabase)
    {
        //string subscriptionDatabase = "SHdHouse";//定阅者本地数据库名
        //string subscriberServer = "rd01";//定阅者服务器
        Boolean isSubKnown = false;
        ServerConnection con = new ServerConnection(publisherName);
        MergePublication mergePub = new MergePublication(publicationName,
                    publicationDatabase, con);
        // Load publication properties from the Publisher.
        try
        {
            if (!mergePub.LoadProperties())
            {
                throw new ApplicationException(Environment.NewLine );
            }

            // Determine if the subscription is already registered at the Publisher.
            foreach (MergeSubscription regSub in mergePub.EnumSubscriptions())
            {
                if (regSub.DatabaseName == publicationDatabase &&
                    regSub.SubscriptionDBName == subscriptionDatabase &&
                    regSub.SubscriberName == subscriberServer &&
                    regSub.SubscriberType == MergeSubscriberType.Local &&
                    regSub.SubscriptionType == SubscriptionOption.Pull)
                {
                    // Subscription is already registered at the Publisher.
                    isSubKnown = true;
                }
            }

            if (!isSubKnown)
            {
                // Register the new subscription at the Publisher.
                mergePub.MakePullSubscriptionWellKnown(subscriberServer,
                     subscriptionDatabase, SubscriptionSyncType.Automatic,
                    MergeSubscriberType.Local, 80.0f);
            }
        }
        catch (InvalidCastException ex)
        {
            throw new ApplicationException(ex.ToString());
        }
        return true;
    }
Beispiel #5
0
    //创建发布以允许使用 Web 同步
    protected void Button6_Click(object sender, EventArgs e)
    {
        // Set the Publisher, publication database, and publication names.
        string publisherName     = SMO.publisherName;       // TextBox8.Text; //"rd01";发布者服务器名
        string publicationName   = SMO.publicationName;     // TextBox4.Text; //"HdHousePub";发布名
        string publicationDbName = SMO.publicationDatabase; // TextBox5.Text;//"HdHouse";发布的数据库名
        string winLogin          = SMO.winLogin;            //TextBox6.Text;//"y";系统帐户
        string winPassword       = SMO.winPassword;         //TextBox7.Text;//"19870312";//该系统帐户密码!

        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 Web synchronization, if not already enabled.
            if ((publication.Attributes & PublicationAttributes.AllowWebSynchronization) == 0)
            {
                publication.Attributes |= PublicationAttributes.AllowWebSynchronization;
            }

            // Enable pull subscriptions, if not already enabled.
            if ((publication.Attributes & PublicationAttributes.AllowPull) == 0)
            {
                publication.Attributes |= PublicationAttributes.AllowPull;
            }

            // Enable Subscriber requested snapshot generation.
            publication.Attributes |= PublicationAttributes.AllowSubscriberInitiatedSnapshot;

            // Enable anonymous access for Subscribers that cannot make a direct connetion
            // to the Publisher.
            publication.Attributes |= PublicationAttributes.AllowAnonymous;

            // 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    = winLogin;
            publication.SnapshotGenerationAgentProcessSecurity.Password = winPassword;

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

            if (!publication.IsExistingObject)
            {
                // Create the merge publication and the Snapshot Agent job.
                publication.Create();
                publication.CreateSnapshotAgent();
            }
            else
            {
                //throw new ApplicationException(String.Format(
                //    "The {0} publication already exists.", publicationName));
                TextBox3.Text += String.Format("发布 {0} 已经存在  \r\n .", publicationName);
            }
        }

        catch (Exception ex)
        {
            // Implement custom application error handling here.
            throw new ApplicationException(String.Format(
                                               "The publication {0} could not be created.", publicationName), ex);
        }
        finally
        {
            conn.Disconnect();
        }
    }
Beispiel #6
0
    //创建发布以允许使用 Web 同步
    protected void Button6_Click(object sender, EventArgs e)
    {
        // Set the Publisher, publication database, and publication names.
        string publisherName = SMO.publisherName;// TextBox8.Text; //"rd01";发布者服务器名
        string publicationName = SMO.publicationName;// TextBox4.Text; //"HdHousePub";发布名
        string publicationDbName = SMO.publicationDatabase;// TextBox5.Text;//"HdHouse";发布的数据库名
        string winLogin = SMO.winLogin;//TextBox6.Text;//"y";系统帐户
        string winPassword = SMO.winPassword; //TextBox7.Text;//"19870312";//该系统帐户密码!

        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 Web synchronization, if not already enabled.
            if ((publication.Attributes & PublicationAttributes.AllowWebSynchronization) == 0)
            {
                publication.Attributes |= PublicationAttributes.AllowWebSynchronization;
            }

            // Enable pull subscriptions, if not already enabled.
            if ((publication.Attributes & PublicationAttributes.AllowPull) == 0)
            {
                publication.Attributes |= PublicationAttributes.AllowPull;
            }

            // Enable Subscriber requested snapshot generation.
            publication.Attributes |= PublicationAttributes.AllowSubscriberInitiatedSnapshot;

            // Enable anonymous access for Subscribers that cannot make a direct connetion
            // to the Publisher.
            publication.Attributes |= PublicationAttributes.AllowAnonymous;

            // 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 = winLogin;
            publication.SnapshotGenerationAgentProcessSecurity.Password = winPassword;

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

            if (!publication.IsExistingObject)
            {
                // Create the merge publication and the Snapshot Agent job.
                publication.Create();
                publication.CreateSnapshotAgent();
            }
            else
            {
                //throw new ApplicationException(String.Format(
                //    "The {0} publication already exists.", publicationName));
                TextBox3.Text += String.Format("发布 {0} 已经存在  \r\n .", publicationName);
            }
        }

        catch (Exception ex)
        {
            // Implement custom application error handling here.
            throw new ApplicationException(String.Format(
                "The publication {0} could not be created.", publicationName), ex);
        }
        finally
        {
            conn.Disconnect();
        }
    }
Beispiel #7
0
    //创建发布
    protected void Button4_Click(object sender, EventArgs e)
    {
        string publisherName = SMO.publisherName;// "rd01";//发布者名
        string publicationName = SMO.publicationName;// "HdHousePub";//发布名
        string publicationDbName = SMO.publicationDatabase;// "HdHouse";//发布的数据库名
        //创建连接
        ServerConnection conn = new ServerConnection(publisherName);
        ReplicationDatabase replicationDatabase = new ReplicationDatabase();
        replicationDatabase.Name = publicationDbName;
        replicationDatabase.ConnectionContext = conn;
        if (!replicationDatabase.LoadProperties())
        {
            Label5.Text = "请确定发布数据库" + publicationDbName + "已存在";
            TextBox3.Text += "请确定发布数据库" + publicationDbName + "已存在  \r\n";
            return;
        }

        if (!replicationDatabase.EnabledMergePublishing)
        {
            replicationDatabase.EnabledMergePublishing = true;
            replicationDatabase.CommitPropertyChanges();
        }

        MergePublication mergePub = new MergePublication();
        mergePub.ConnectionContext = conn;
        mergePub.DatabaseName = publicationDbName;
        mergePub.Name = publicationName;
        //mergePub.SnapshotGenerationAgentProcessSecurity
        //mergePub.Attributes |= PublicationAttributes.;
        mergePub.Create();
        mergePub.CreateSnapshotAgent();
    }
Beispiel #8
0
 //删除
 protected void Button15_Click(object sender, EventArgs e)
 {
     ServerConnection sconn = new ServerConnection(SMO.publisherName);
     try
     {
         MergePublication mpc = new MergePublication();
         mpc.Name = SMO.publicationName;
         mpc.DatabaseName = SMO.publicationDatabase;
         mpc.ConnectionContext = sconn;
         if (mpc.IsExistingObject)
         {
             mpc.Remove();
         }
         else
         {
             TextBox3.Text = "发布" + SMO.publicationName + "的定义不正确,或者发布不存在。\r\n";
         }
         ReplicationDatabase rld = new ReplicationDatabase();
         rld.ConnectionContext = sconn;
         rld.Name = SMO.publicationName;
         if (rld.LoadProperties())
         {
             rld.EnabledMergePublishing = false;
             rld.CommitPropertyChanges();
         }
         else
         {
             TextBox3.Text = "请验证" + SMO.publicationDatabase + "数据库是否存在。\r\n";
         }
     }
     catch (Exception ex)
     {
         throw new ApplicationException(String.Format(
             "The publication {0} 无法删除.", SMO.publicationName), ex);
     }
     finally
     {
         sconn.Disconnect();
     }
 }