OpenAccess: Shouldn't this be easier...?

3 posts, 0 answers
  1. Scott
    Scott avatar
    68 posts
    Member since:
    Nov 2011

    Posted 27 Dec 2011 Link to this post

    I guess I'm just using OpenAccess incorrectly, because it keeps breaking inconsistently... one moment the code works perfectly fine, then when I'm off working on another screen and go back to previous sections in the website, OpenAccess starts throwing Invalid Handle and Shared Memory errors.... Can you not use OpenAccess as written in the two code snippets below??

    ****** Snippet #1 ********
    public IList<Customer> GetCustomers(Guid userId)
    {
        IList<Customer> customers = null;
        using (UserAdminContext dbContext = new UserAdminContext("AdminConnection"))
        {
            var query = from c in dbContext.Customers
                     from a in c.UserCustomerAssociations
                      where a.UserId == userId
                    select new Customer() { CustomerNumber = c.CustomerNumber, CompanyName = c.CompanyName, Identifier = c.Identifier };
                    
         customers = query.ToList<Customer>();
        }
        return customers;
    }

    ******** Snippet #2 **********
    public IDictionary<string, string> GetGeoLevels()
    {
        IDictionary<string, string> levels = new Dictionary<string, string>();
        using (ParentChildSummaryContext dbContext = new ParentChildSummaryContext("PCSConnection"))
        {
            var retailer = (from r in dbContext.SupplyChainRetailers
                                 where r.RetailerCode == "LOW"
                                 select r).FirstOrDefault();
            
            if (retailer != null)
            {
                levels.Add("G1", retailer.Attribute1);
                levels.Add("G2", retailer.Attribute2);
                levels.Add("G3", retailer.Attribute3);
                levels.Add("G4", retailer.Attribute4);
                levels.Add("G5", retailer.Attribute5);
            }
        }
        return levels;
    }

    I don't believe these are very complex by any stretch of the imagination and worry that when I do get to more complex scenarios it will crash and burn if it can't even do these simple tasks....?? :(

  2. Thomas
    Admin
    Thomas avatar
    590 posts

    Posted 27 Dec 2011 Link to this post

    Hi Scott,

    I have seen such exceptions in the past when the database server was limiting the number of open connections in parallel. As you have indicated in another post, this could come from to many database contexts being used, all pointing to the same logical database.
    As already stated in the other posts reply, please use one domain model, that make the code also easier.

    Kind regards,
    Thomas
    the Telerik team

    Q3’11 of Telerik OpenAccess ORM is available for download. Register for the What's New in Data Tools webinar to see what's new and get a chance to WIN A FREE LICENSE!

  3. DevCraft banner
  4. Scott
    Scott avatar
    68 posts
    Member since:
    Nov 2011

    Posted 27 Dec 2011 Link to this post

    Seems like my other post is related, so see my response there at link below:

    See here
Back to Top