public static void CreateNewConnection(string sourceServer, string targetServer, string connectionName)
        {
            try
            {

                // set a directory server context for the source server
                DirectoryContext sourceContext = new DirectoryContext(
                                                    DirectoryContextType.DirectoryServer,
                                                    sourceServer);

                // set a directory server context for the target server
                DirectoryContext targetContext = new DirectoryContext(
                                                    DirectoryContextType.DirectoryServer,
                                                    targetServer);

                // bind to a specific domain controller to serve as the
                // source of a replication connection
                DomainController sourceDc =
                                    DomainController.GetDomainController(sourceContext);

                ReplicationConnection connection = new ReplicationConnection(
                                                        targetContext,
                                                        connectionName,
                                                        sourceDc);

                // set change notification status
                connection.ChangeNotificationStatus = NotificationStatus.IntraSiteOnly;

                // create a customized replication schedule
                ActiveDirectorySchedule schedule = new ActiveDirectorySchedule();
                schedule.SetDailySchedule(HourOfDay.Twelve,
                                          MinuteOfHour.Zero,
                                          HourOfDay.Fifteen,
                                          MinuteOfHour.Zero);

                schedule.SetSchedule(DayOfWeek.Sunday,
                                     HourOfDay.Eight,
                                     MinuteOfHour.Zero,
                                     HourOfDay.Eleven,
                                     MinuteOfHour.Zero);

                schedule.SetSchedule(DayOfWeek.Saturday,
                                     HourOfDay.Seven,
                                     MinuteOfHour.Zero,
                                     HourOfDay.Ten,
                                     MinuteOfHour.Zero);

                connection.ReplicationSchedule = schedule;
                connection.ReplicationScheduleOwnedByUser = true;

                // save the new connection to the directory
                connection.Save();
                Console.WriteLine("\nNew replication connection created successfully\n" +
                  "from server {0} to {1}.\n The connection appears in the NTDS " +
                  "settings of {1}", sourceServer, targetServer);

            }
            catch (Exception e)
            {
                Console.WriteLine("\r\nUnexpected exception occured:\n{0}:{1}",
                                  e.GetType().Name, e.Message);
            }
        }