Using Multiple Database Access

To access multiple JADE databases, you must supply connection details via the appropriate JoobContext constructor. This can take the form of an existing JoobConnection object, or it can be via a JoobConnectionStringBuilder object, as shown in the following example.

<BLOCK 1A>
using (JoobContext context = new JoobContext 
                      (JoobConnectionStringBuilder.CreateFromConfig("LocalJade")))
{
    // Established context to database with schema MultipleDb1 as 
    // specified by the "LocalJade" connection string in the app.config
     <BLOCK 2A>
    using (JoobContext remoteContext = new JoobContext 
                      (JoobConnectionStringBuilder.CreateFromConfig("RemoteJade")))
    {
        // Established context to database with schema MultipleDb2 as 
        // specified by "RemoteJade" connection string.
         <BLOCK 3>
    }
    <BLOCK 2B>
}
<BLOCK 1B>

The app.config file reads as follows.

<connectionStrings>
  <add name="RemoteJade" providerName="JadeSoftware.Joob.JoobConnection" 
    connectionString="DataSource=tcpip://remoteHost:6005/7bf0f9cd-680a- 
    e111-9eaf-5ae520524153;ConfigFile=\\remoteHost\C:\Jade\system\jade.ini; 
    Schema=MultipleDb2;IntegratedSecurity=True"></add>
  <add name="LocalJade" providerName="JadeSoftware.Joob.JoobConnection" 
    connectionString="DataSource=C:\Jade\system;ConfigFile=C:\Jade\system\jade.ini;
    Schema=MultipleDb1;IntegratedSecurity=True"></add>
</connectionStrings>

The model for multiple database access follows the pattern of requiring a live JoobContext before a JoobObject can interact with its database.

When an appropriate JoobContext has been instantiated for a database, JoobObject instances from that database can be retrieved, created, and de-referenced. Each JoobObject instance knows the database to which it belongs and provided that a JoobContext is alive for its database on the current thread, JoobObject manipulation can occur.

For example, a JoobObject variable of a MultipleDb2 class can be declared in BLOCK 1A or BLOCK 2A. You can set, get, or invoke JADE schema-defined properties and methods only from within BLOCK 3. You can locate instances of classes only from schema MultipleDb2 within BLOCK 3. However, you can manipulate instances of classes from MultipleDb1 within BLOCK 2A, BLOCK 2B, and BLOCK 3.