This is a migrated thread and some comments may be shown as answers.

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

2 Answers 54 Views
Getting Started
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Scott
Top achievements
Rank 2
Scott asked on 27 Dec 2011, 04:19 PM
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 Answers, 1 is accepted

Sort by
0
Thomas
Telerik team
answered on 27 Dec 2011, 07:18 PM
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!

0
Scott
Top achievements
Rank 2
answered on 27 Dec 2011, 07:53 PM
Seems like my other post is related, so see my response there at link below:

See here
Tags
Getting Started
Asked by
Scott
Top achievements
Rank 2
Answers by
Thomas
Telerik team
Scott
Top achievements
Rank 2
Share this question
or