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

Switch Connections

1 Answer 68 Views
Data Access Free Edition
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Wesley
Top achievements
Rank 1
Wesley asked on 18 Aug 2014, 09:37 PM
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. 

1 Answer, 1 is accepted

Sort by
0
Kaloyan Nikolov
Telerik team
answered on 22 Aug 2014, 04:28 AM
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)?


Regards,
Kaloyan Nikolov
Telerik
 
OpenAccess ORM is now Telerik Data Access. For more information on the new names, please, check out the Telerik Product Map.
 
Tags
Data Access Free Edition
Asked by
Wesley
Top achievements
Rank 1
Answers by
Kaloyan Nikolov
Telerik team
Share this question
or