Switch Connections

2 posts, 0 answers
  1. Wesley
    Wesley avatar
    1 posts
    Member since:
    Jun 2011

    Posted 18 Aug 2014 Link to this post

    I need to dynamically switch connection strings depending on what setting I have in my web.config

    The databases all have the exact same schema, but I want to read form different databases based on the setting connectionString

        public virtual IQueryable<PurchaseOrder> GetAll()
                var dataContext = new Minopex.GLUE.DimensionsModel(connectionString); // switch the connection string here

                IQueryable<PurchaseOrder> allEntities = dataContext.GetAll<PurchaseOrder>();

                return allEntities;

    This works for simple classes with no relationships, but when I try it with on classes that have relationships, it gives me this error ...

    Type is enhanced and registered, but not available from the database class meta data. This can be caused by a wrong connection id or configuration. Parameter name: type Actual value was PurchaseOrder.

    Maybe I'm going about this the wrong way. 

  2. Kaloyan Nikolov
    Kaloyan Nikolov avatar
    118 posts

    Posted 21 Aug 2014 Link to this post

    Hello Wesley,

    The approach with injecting different connection string to access different databases with one and the same schema is valid and it should work. 

    The exception you mention indicates that you are trying to use a class in the GetAll() method which most probably is defined in another OpenAccessContext. To work in this way you should have a single model and mapping for it. 

    How many mappings do you have in your project? What kind of mapping do you use (RLNQ, Fluent or Attribute)?

    Kaloyan Nikolov
    OpenAccess ORM is now Telerik Data Access. For more information on the new names, please, check out the Telerik Product Map.
  3. DevCraft banner
Back to Top