More in this section

Forums / Developing with Sitefinity / Error coming while submitting values to Form

Error coming while submitting values to Form

2 posts, 0 answered
  1. Harshil
    Harshil avatar
    5 posts
    19 Mar 2014
    09 Apr 2015
    Link to this post

    We have created a custom webform to store values in a "Form" of Sitefinity but it gives an error when two concurrent request comes for saving data back to "Form" of Sitefinity.

    Below is the code which we have written to save information:

    using (FormsManager manager = new FormsManager())
                manager.Provider.SuppressSecurityChecks = true;
                var form = manager.GetFormByName("sf_graduateform");
                if (form != null)
                    FormEntry entry = manager.CreateFormEntry(String.Format("{0}.{1}", manager.Provider.FormsNamespace, form.Name));
                    entry.SetValue("FormTextBox_C001", FirstName.Text);
                    entry.SetValue("FormTextBox_C002", LastName.Text);
                    entry.SetValue("FormTextBox_C003_0", Email.Text);
                    entry.SetValue("FormTextBox_C004_0", Telephone.Text);
                    entry.SetValue("FormDropDownList_C005", CountryOfResidence.SelectedItem.Value);
                    entry.SetValue("FormMultipleChoice_C006", legal_yes.Checked ? "Yes" : "No");
                    if (UploadDocumentation.HasFile)
                        //check filesize
                        const int maxFileSize = 5242880;
                        int fileSize = UploadDocumentation.PostedFile.ContentLength;
                        if (fileSize > maxFileSize)
                            UploadSizeWarning.Text = "The file should be under 5MB";
                    string providerName = "SystemLibrariesProvider";
                    LibrariesManager librariesManager = new LibrariesManager(providerName);
                    var document = librariesManager.GetDocuments().ToList().FirstOrDefault(d => d.Title == UploadDocumentation.FileName && !d.IsDeleted);
                    document = UploadPDF(document, librariesManager);
                    entry = AddLinkToResponse(document, entry);
                    entry.SetValue("FormParagraphTextBox_C008", additional_links.Text);
                    entry.IpAddress = SystemManager.CurrentHttpContext.Request.UserHostAddress;
                    entry.SubmittedOn = DateTime.UtcNow;
                    //entry.UserId = ClaimsManager.GetCurrentUserId();
                    entry.ReferralCode = form.FormEntriesSeed.ToString(CultureInfo.CurrentUICulture.Name);

    The issue is that when we write "form.FormEntriesSeed++;" and when we get concurrent requests it crash down as per the attached screenshot (PFA: error_while_updating.png).

    We checked it after removing above code but as per the link it is written that we must write above given code.

    One thought in our mind is that we can apply the lock on the whole code given above but we are very unsure whether it is proper way or not.

    Please provide your kind inputs in this matter.

    Harshil Shukla
  2. Sabrie Nedzhip
    Sabrie Nedzhip avatar
    534 posts
    17 Aug 2017
    14 Apr 2015
    Link to this post
    Hello Harshil,

    We have just replied in the ticket you have opened related to this issue. I am pasting here the suggestions from the ticket reply for your convenience:

    I came up with two possible solutions for your case:

    1. The first one would be to first create the form entry, increment the seed and set the referral and save changes. After that, process the form upload and associate the uploaded file with the form entry.

    2. The second approach would be to leave your code as is and first create the entry without incrementing the seed, and save the changes. This will ensure that the form entry has been created ok and after that, use a try catch to increment the seed and set the referral: With this approach, the entry will be created as expected always and the end user will not a get an error under any circumstances. In case there is a problem when the seed is updated, the error will be handled and the entry will simply appear without a number in the backend.

    Sabrie Nedzhip
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
2 posts, 0 answered