Here are answers to questions about MicroStation® Database Linkages that are posted from time to time on the Bentley Discussion Groups. The questions are posted by MDL and VBA developers as well as database developers.

Bentley Systems have a Technical Note about databases and MicroStation: Databases and MicroStation V8 FAQ

Q What is an MSLINK?

When you link a database to graphic elements in MicroStation, you create a correspondence between a row in a database table and the element. The table that contains the row must have a column named MSLINK, having datatype 32-bit integer. The element has a corresponding MSLINK 32-bit value, known as the database linkage or database attribute. There is more information about MSLINK.

Q How does the database provided by MicroStation work?

A MicroStation does not provide a database. It provides a database server that communicates with an external relational database. Relational databases that work with MicroStation include Oracle Enterprise Server™, Microsoft SQL Server, and Microsoft Access™. For more information, visit the Bentley Systems web site.

There are some example files and databases delivered with MicroStation. The example database is located in …

X:\Program Files\Bentley\Program\MicroStation\database\odbc\examples\

The example files are located in …

X:\Program Files\Bentley\Workspace\Projects\Examples\Mapping\dgn

Where X is the drive where your MicroStation installation is located. This is usually the C drive.

Q I would like to know more about the link between objects and the database.

A Each object (graphic element) that is linked to a database has a database linkage attached to the element. Sometimes this is called the MSLINK in Bentley Systems' and other literature. When you use MicroStation's Analyse tool (the i icon) on an element that has a linkage, the Attributes tab will reveal the linkage in Hexadecimal.

Each linkage comprises …

In C or C++ these are long (32-bit) integers; in VB or VBA these are Long datatypes. The Entity ID is a reference to the database table that contains the MSLINK column. The name of the table is found in the [mscatalog] table. Here's an SQL statement that reveals a table name given its Entity ID …

SELECT tableName FROM mscatalog WHERE entityNum=20;

The value 20 is an example: it may not exist in your [mscatalog] table. Examine the data in [mscatalog] and substitute an alternative. You can list all the catalogy rows like this …

SELECT * FROM mscatalog ORDER BY tableName;

Suppose you have a table in your database named [myTable]. To link with a MicroStation element, there are two conditions …

The entry in [mscatalog] defines your table's entity ID. For example …

Column [tablename] [entityid]
Data myTable 20

Your graphic element database linkage must have the entity ID of 20 to link with your [myTable] table. The element's MSLINK value determines the row in [myTable] that holds data about that element.

Q How do I link an object to multiple tables?

A An element may have multiple database linkages. That is, there may be one or more [mslink]|[entity id] pairs of information attached to an element from more than one table.

Each linkage will refer to a different table. For example, if you have tables [myTable1] and [myTable2], then [mscatalog] might have these entries …

[mscatalog]
Column [tablename] [entityid]
Data myTable1 20
Data myTable2 21

If your element is linked to both tables, the database linkage attached to the element could be …

MSLINK Entity ID
1234 20
4567 21

The tables could have rows like this …

[myTable1]
MSLINK Col2 Col3
1234 Data 1234 MoreData 1234
[myTable2]
MSLINK Col2 Col3
4567 Value 4567 Another 4567

Q How do I use Visual Basic (VB) to communicate with MicroStation and a database?

A MicroStation V8 includes Visual Basic for Applications (MVBA). MVBA includes functions for reading and creating database linkages on graphic elements. MVBA functions can be used from VB by creating a reference to the MicroStation.Application object, then calling the methods on that object.

MVBA does not, however, provide a mechanism to communicate with a database. Instead, you can use technology such as Microsoft's ActiveX Data Objects (ADO) to connect to a database and exchange data. You can download the ADO libraries and API here.

The VBA project in this ZIP Archive demonstrates how Visual Basic can interrogate the linkage between MicroStation V8 and the delivered Access database mentioned above.

Q Can I store my data (in my case, object name) without using an external database?

A Yes, through one of two technologies that are part of MicroStation …

Tag Elements

FlexiTable™ uses tags as a data source to create a schedule table that is displayed in MicroStation. However, it's a little more versatile than just a tag editor, because those data can be derived from many different data sources. FlexiTable also exports data in a number of ways.

Tag Elements are available through MicroStation's Tags toolbox. They are graphic objects that may be manipulated and printed like any other element. What's different is that there are built-in tools to query and report on tag data.

Tags Elements contain your data that are associated with a host element. They are part of the DGN file and require no external database or application. MicroStation's tag functionality includes a reporting mechanism. You can save the data from tagged elements to a CSV or XML file.

MicroStation lets you define a named Tag Set that contains a number of Tag definitions. This is analogous to defining the columns of a table in a database schema.

Some applications created by LA Solutions use Tag Elements to store data. For example, AssetPlanner™ records room areas in tags, includes HTML reports. Its strength is that it automatically updates its area tag value as you edit a room's boundary.

XML Fragments

FlexiTable™ displays data in tabular form in MicroStation. It persists data in XML fragments to enable its editing capability. However, it's a little more versatile than just an XML fragment editor, because those data can be derived from many different data sources. FlexiTable also exports data in a number of ways.

XML Fragments are implemented with technology introduced with MicroStation V8.1. An XML Fragment contains data embedded in an XML element. The XML element and its contained data are attached to a MicroStation graphic element as a data linkage.

Currently there are no user tools available for XML Fragments. The first Bentley Systems application to use XML Fragments is MicroStation GeoGraphics 2004 Edition, which provides GIS analysis, labelling, and reporting using XFM technology.

There is an XML Fragment API for MDL but not for MicroStation VBA. The MDL API provides full access not only to XML Fragments, but also to stand-alone XML data that is part of the DGN file but not associated with any particular graphic element.