Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Søren Linaa 255 posts 208 karma points
    Jun 23, 2016 @ 08:40
    Søren Linaa
    0

    Working with Record data = There is already an open DataReader associated

    Hi

    I'm trying to get Umbraco Forms records data in Umbraco 7.4.3

    I'm following the documentation here: https://our.umbraco.org/documentation/Addons/UmbracoForms/Developer/Working-With-Data/

    My purpose is to get all records from a form listed - related to the current page

    It is resulting in this error There is already an open DataReader associated with this Command which must be closed first.

    I have tried isolating, but nothing seems to work. So I'm wondering whats the correct way of getting data from Umbraco Forms.

    Cheers

  • Dennis Aaen 4499 posts 18254 karma points admin hq c-trib
    Jun 26, 2016 @ 09:05
    Dennis Aaen
    0

    Hi Søren,

    With the Razor code below you should get all the approved comments from your form.

    @using Umbraco.Forms.Mvc.DynamicObjects
    
    <ul id="comments">
     @foreach (dynamic record in Library.GetApprovedRecordsFromPage(@CurrentPage.Id).OrderBy("Created"))
     {
         <li>
              @record.Created.ToString("dd MMMM yyy")
              @if(string.IsNullOrEmpty(record.Website)){
                 <strong>@record.Name</strong>
              }
              else{
                 <strong>
                   <a href="@record.Website" target="_blank">@record.Name</a>
                 </strong>
              }
             <span>said</span>
            <p>@record.Comment</p>
         </li>
      }
    </ul>
    

    Hope this helps, if not could you please try to paste the current code that you have right now.

    Best,

    /Dennis

  • Søren Linaa 255 posts 208 karma points
    Jul 04, 2016 @ 10:58
    Søren Linaa
    0

    Hi Dennis,

    I'm using exactly your code in an empty view to avoid any other code to interrupt.

    I have upgraded Umbraco forms to 4.3.2

    Running Umbraco 7.4.3

    I get this error message There is already an open DataReader associated with this Command which must be closed first.

    when I try to get the records

    DynamicRecordList list = Library.GetApprovedRecordsFromPage(CurrentPage.Id);
    
  • Warren Buckley 2106 posts 4836 karma points MVP ∞ admin hq c-trib
    Jul 06, 2016 @ 11:03
    Warren Buckley
    0

    Hello Soren,
    Can you send over the example you are using please?

    As your one liner does not match up from Dennis's example he sent you.

    You could try adding .ToList() to the end of your line to see if this helps resolve your problem.

    Thanks,
    Warren

  • Søren Linaa 255 posts 208 karma points
    Jul 07, 2016 @ 09:44
    Søren Linaa
    0

    Hi Warren,

    The one liner is the same - It should also work this way. I have tried Dennis's with the same result.

    My code is isolated this - which returns in the error

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    @using System.Linq;
    @using Umbraco.Forms.Mvc.DynamicObjects;
    
    @{
        DynamicRecordList list = Library.GetApprovedRecordsFromPage(Model.Content.Id);
    }
    

    I'm am using the only documentation there is https://our.umbraco.org/documentation/Products/UmbracoForms/Developer/Working-With-Data/

    I think I will write my own sql - this is too weird.

  • Warren Buckley 2106 posts 4836 karma points MVP ∞ admin hq c-trib
    Jul 08, 2016 @ 07:58
    Warren Buckley
    0

    Morning Soren,
    Sorry this is not working. I will test & verify this morning and get back to you shortly.

    Can you please confirm what version of Umbraco Forms you are using?

    Thanks,
    Warren

  • Warren Buckley 2106 posts 4836 karma points MVP ∞ admin hq c-trib
    Jul 08, 2016 @ 10:04
    Warren Buckley
    101

    OK I have found time to test & verify this.
    This is working OK for me in the latest version of Umbraco.

    Is there anything unusual about your Database or connection string that I may need to be aware about?

    Full SQL Server, SQL Azure, SQL CE DB or...?

    As an alternative for now you could use the following:

    @{
       using (var formStorage = new FormStorage())
       {
           using (var recordStorage = new RecordStorage())
           {
               var form = formStorage.GetForm(Guid.Parse("ede58fd2-9eff-4f88-a5d6-053042983681"));
               var records = recordStorage.GetAllRecords(form).Where(x => x.UmbracoPageId == Model.Content.Id && x.State == FormState.Approved).ToList();
           }
       }
    }
    

    Rather than doing this directly in a view. It would be better of course to do this logic in a controller and pass records to your view, but of course there are many ways to do the same thing with Umbraco.

    Thanks,
    Warren :)

  • Søren Linaa 255 posts 208 karma points
    Jul 11, 2016 @ 08:15
    Søren Linaa
    1

    Hi Warren,

    It was exactly what I was trying to figure out how to do. Your method with FormStorage // Recordstorage did the trick.

    This way is also more easy to filter a list.

    Regarding the error - I'm on a SQL 2008 - don't know if there are any issues here

  • Mads Krohn 211 posts 504 karma points c-trib
    Oct 23, 2018 @ 12:13
    Mads Krohn
    0

    Hi Warren

    I know this issue is old, but it's still not fixed. The workaround you posted is useless when you use the same form on multiple pages and want to show only comments made on that page. Right now we have a comments form spanning multiple news pages. GetAllRecords() retrieves all 2500 comments, which takes around a minute, then we can do the filtering. It's just not feasible. And the issue with the open data reader using the old Library classes are still present, which leads me to believe that 0 hours have gone into fixing this issue, while being over 2 years old. /rant

  • Dennis Adolfi 1082 posts 6446 karma points MVP 5x c-trib
    Jul 08, 2016 @ 16:23
    Dennis Adolfi
    4

    Whenever i get the "There is already an open DataReader associated with this Command which must be closed first." error (happens sometimes) it's always solved for me by adding MultipleActiveResultSets=true in the connectionstring.

    Could be worth a shot!

    Similar issue from StackOverflow: http://stackoverflow.com/questions/6062192/there-is-already-an-open-datareader-associated-with-this-command-which-must-be-c

  • Al Nicholl 15 posts 97 karma points
    Nov 24, 2016 @ 15:51
    Al Nicholl
    1

    Dennis,

    You, sir, are a legend. Fixed the same problem for me.

    h5yr

    Cheers,

    Al

  • Dennis Adolfi 1082 posts 6446 karma points MVP 5x c-trib
    Nov 25, 2016 @ 08:09
    Dennis Adolfi
    0

    Thank you Al! :)

    Glad it worked out for you!!

    Have a good weekend!

Please Sign in or register to post replies

Write your reply to:

Draft