To instruct Active Query Builder to show metadata from some other databases or linked servers, you just need to add few lines of code before initializing the Database Schema Tree.
To add a database:
MetadataItem database = queryBuilder1.MetadataContainer.AddDatabase("DbName");
To add a linked server and all it's databases:
MetadataItem server = queryBuilder1.MetadataContainer.AddServer("ServerName");
To add a database from linked server:
MetadataItem server = queryBuilder1.MetadataContainer.AddServer("ServerName");
MetadataItem database = server.AddDatabase("DbName");
Note that adding a database or a server using this helper method prevents loading of other databases or servers from the parent node. In the same way you can prevent loading of unnecessary schemas from a database. It's quite simple for Oracle database server which does not support multiple databases:
MetadataItem schema = queryBuilder1.MetadataContainer.AddSchema("SchemaName");
For those database servers that support multiple databases, use the following code:
// load the first level of the Metadata Container which should have the default database
queryBuilder1.MetadataContainer.Items.Load(MetadataType.Database, false);

// get list of loaded databases
IList databases = queryBuilder1.MetadataContainer.Items.GetList(MetadataType.Database);

// find the default database in the list
foreach (MetadataItem database in databases)
    if (database.Default)
        MetadataItem schema = database.AddSchema("SchemaName");
Executing the code snippets above won't actually load metadata, but only add the root nodes for further loading on demand. After adding the necessary items you may initialize the Database Schema Tree as usual:
During the initialization process the tree will be expanded according to the QueryBuilder.DatabaseSchemaTreeOptions.DefaultExpandLevel property. Note that increasing of this property value will lead to increased initialization time as metadata loading is performed on expansion of the Database Schema Tree nodes.

Some users wants to load metadata from different servers that are not linked with each other. Although it is possible to do this, and the component will be able to build a query using objects from different servers, note that there will be no way to execute such queries, until you create your own query execution engine. If this doesn't stop you, follow the steps below.
  1. Set the right syntax and metadata providers for the first database server and connect to it.
  2. Load Metadata by calling the MetadataContainer.LoadAll(true) method. (The withFields parameter set to true instructs to load fields for each database object that may take a long time for large database schema, so please be patient.)
  3. Set the right syntax and metadata providers for the next database server and connect to it.
  4. Add new database (or server) as described above.
  5. Load Metadata from the database by calling the Metadataitem.LoadAll(true) method, where MetadataItem is the newly added database object.
Repeat steps 3-5 for all subsequent databases and servers that you want to load metadata from. After that you may save all metadata to the XML file and use it afterwards.

This article was helpful for 1 person. Is this article helpful for you?