What would be the best way to store the RecurrenceRule and the RecurrenceParentId in the database? Would varchar and int, respectively, be the best data types to use in SQL?
Also, what would be the best way to translate a recurrence rule into something I can use somewhere else? For example, if I wanted to populate a DropDownList control with appointment titles and then upon SelectedIndexChanged, populate the second DropDownList with all of the available (recurring) time slots, would that be possible? If so, what would be the best way of going about it?
Thanks.
7 Answers, 1 is accepted
"What would be the best way to store the RecurrenceRule and the RecurrenceParentId in the database? Would varchar and int, respectively, be the best data types to use in SQL?"
The recommended storage for RecurrenceRule is varchar with maximum size of about 1024 characters. Most recurrence rules take much less and the extra space is needed for appending exception dates.
The RecurrenceParentID field is a foreign key pointing to the primary key, so it must be of the same type as the PK.
In order to make sense of the recurrence rule it should be parsed first. The Telerik.Web.UI.RecurrenceRule class makes this task easy. The following example first builds a recurrence rule, then converts it to string (as for storage in a database) and finally parses it and outputs the occurrence dates:
using System; |
using Telerik.Web.UI; |
namespace RecurrenceExamples |
{ |
class ParsingExample |
{ |
static void Main() |
{ |
// Creates a sample appointment that starts at 6/1/2007 3:30 PM (local time) and lasts half an hour. |
Appointment recurringAppointment = new Appointment("1", Convert.ToDateTime("6/1/2007 3:30 PM"), |
Convert.ToDateTime("6/1/2007 4:00 PM"), "Sample appointment"); |
// Creates a recurrence range, that specifies a limit of 10 occurrences for the appointment. |
RecurrenceRange range = new RecurrenceRange(); |
range.Start = recurringAppointment.Start; |
range.EventDuration = recurringAppointment.End - recurringAppointment.Start; |
range.MaxOccurences = 10; |
// Creates a recurrence rule to repeat the appointment every 2 hours. |
HourlyRecurrenceRule rrule = new HourlyRecurrenceRule(2, range); |
Console.WriteLine("The appointment recurs at the following times"); |
foreach (DateTime occurrence in rrule.Occurrences) |
{ |
Console.WriteLine("\t{0}", occurrence); |
} |
Console.WriteLine(); |
// Prints the string representation of the recurrence rule: |
string rruleAsString = rrule.ToString(); |
Console.WriteLine("Recurrence rule:\n\n{0}\n", rruleAsString); |
// The string representation can be stored in a database, etc. |
// ... |
// Then it can be reconstructed using TryParse method: |
RecurrenceRule parsedRule; |
RecurrenceRule.TryParse(rruleAsString, out parsedRule); |
Console.WriteLine("After parsing (should be the same):\n\n{0}", parsedRule); |
} |
} |
} |
More information in the online documentation.
Kind regards,
Tsvetomir Tsonev
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
The recommended size is 1024 for optimization purposes, as it is rarely the case when there are so many exception dates that the total string count exceeds 1024 characters.
With that said, there should be no issue with increasing the number of characters limit.
Regards,
Peter Milchev
Progress Telerik
I have an application that require lots of exceptions. At certain point, radscheduler stopped recording those.
The pattern or appointments that fail accepting the change is that the fielr RecurrenceRule are near the 1024 limit. I have doubled the field size to 2048 but still radscheduler will not process the new exception. Is there another place on radscheduler that I have to make an adjustment ? Database is SQL server 2014 and my Telerik version is UI for ASP.NET AJAX R1 2019 SP1 (version 2019.1.215)
Hello Vicente,
The RadScheduler does not care about the length of the recurrence rules, so you can set the field size to an even bigger number.
There might be a possibility if when trying to save the recurrence rule, the SQL cut the text and that would lead to an invalid recurrence rule.
Please try creating a new appointment to the data base and start adding exceptions until the issue is observed again. It should work properly until the limit of the column size is met.
Regards,
Peter Milchev
Progress Telerik