Telerik OpenAccess Classic

Telerik OpenAccess ORM Send comments on this topic.
How to: Connect to Multiple Databases
Programmer's Guide > OpenAccess ORM Classic (Old API) > OpenAccess Tasks > Connections and Data Store Management > How to: Connect to Multiple Databases

Glossary Item Box

This documentation article is a legacy resource describing the functionality of the deprecated OpenAccess Classic only. The contemporary documentation of Telerik OpenAccess ORM is available here.

This topic describes how to produce a solution that uses multiple database-models generated by OpenAccess. For the purpose an example will be presented where the scenarion is the following: there are two databases, WorkDB and ArchiveDB. WorkDB stores information of all the current workers in a company and ArchiveDB for the workers that no longer work in that company.

To configure the desired data-models:

  1. Create a class library project named for example "Archive" where the model for the ArchiveDB will be created
  2. Create the classes that define the ArchiveDB model
  3. Enable the project to use OpenAccess and set a unique Connection Id like "ArchiveDbConnection"
  4. Use the Forward-Mapping wizard to define any additional settings for the model

OpenAccess uses the App.config file of a project to set its database connection details. They are stored in the “connections” section and should look like the following:

App.config Copy Code
<connection id="ArchiveConnection">


   5. Create another class library project and do the same steps for the WorkDB model

App.config Copy Code
<connection id="WorkConnection">


Setting up the executable project

After these steps are taken an executable project needs to be created for example a Windows Forms application.

  1. Create a new Windows Forms application
  2. Make reference to both ArchiveDB and WorkDB class library projects
  3. Enable the application to use OpenAccess
  4. The generated App.config file should contain "references" section where it is pointed which assemblies that use OpenAccess are referred by our application
App.config Copy Code
<reference assemblyname="Archive" />
<reference assemblyname="CurrentWork" />


That way OpenAccess looks in the app.config files of the referenced assemblies and can use all the settings specified in them. 

  In the executable project the developer is now able to use both databases and all that is required is to pass the corresponding connectionId parameter to the Database.Get() method:

C# Copy Code
Database archiveDb= Database.Get( "ArchiveConnection" );
IObjectScope archiveScope = archiveDb.GetObjectScope();
Database workDb = Database.Get(
"WorkConnection" );
IObjectScope workScope = workDb.GetObjectScope();  
VB.NET Copy Code
Dim archiveDb As Database= Database.Get("ArchiveConnection")
Dim archiveScope As IObjectScope = archiveDb.GetObjectScope()
Dim workDb As Database = Database.Get("WorkConnection")
Dim workScope As IObjectScope = workDb.GetObjectScope()

From this point on it is fairly easy to use both object scopes in our business logic and update or extract information from the two databases. This approach provides  better organization of the solution and the dependencies between the deferent projects in it.