Developer Documentation Library > Data Model > Accessing the UNICOM Intelligence Data Model > Working with the Case Data Model > Connecting to the UNICOM Intelligence Data Model > Connecting using an open MDM document
 
Connecting using an open MDM document
You can use the CreateDocumentObjectString method of the UNICOM Intelligence OLE DB Provider's DataLinkHelper class to create a string for an instantiated MDM Document object for use when setting the MR Init MDM Document connection property. For example, in Visual Basic:
DataLinkHelper
CreateDocumentObjectString(Document As Object) As String
This method is required because it is not possible to set an object as a connection property in ADO. The method creates a string representation of the interface pointer MEOW (Microsoft Extended Object Wire) signature. The MEOW is a serialized interface reference used for inter-apartment activation.
To use the DataLinkHelper class in Visual Basic, add UNICOM Intelligence DM-n OLE DB Type Library to the project references.
Example 1
This mrScriptBasic example opens the museum.mdd sample MDM Document,, connects to the open Document, executes a query, and writes out the contents of the ADO recordset. You can run this script using UNICOM Intelligence Professional or alternatively, copy and paste the code into a text file that has a .mrs extension and run the file using mrScript Command Line Runner.
Dim MyDocument, DataLinkHelper, ConnectionString
Dim adoConnection, adoRS, Field

' Open the museum.mdd sample MDM Document
Set MyDocument = CreateObject("MDM.Document")
MyDocument.Open(" [INSTALL_FOLDER]\IBM\SPSS\DataCollection\7\DDL\Data\Data Collection File\museum.mdd", , _
MDMLib.openConstants.oREAD)

' Now connect to the open Document
Set DataLinkHelper = CreateObject("MROLEDB.DataLinkHelper")

ConnectionString = "Provider=mrOleDB.Provider.2;MR Init MDM Document=" + _
DataLinkHelper.CreateDocumentObjectString(MyDocument)

Set adoConnection = CreateObject("ADODB.Connection")
adoConnection.Open(ConnectionString)

' Run a query against the data source
Set adoRS = adoConnection.Execute("SELECT respondent.serial FROM vdata")

' Output the contents of the ADO recordset
adoRS.MoveFirst()

Do Until adoRS.EOF
For Each Field in adoRS.Fields
Debug.Log(Field.Value)
Next
adoRS.MoveNext()
Debug.Log("-- END OF ROW --")
Loop

adoConnection.Close()
Example 2
A similar example in VB.NET.
Dim MDMDoc As New MDMLib.Document
Dim DataLinkHelper As New MROLEDBLib.DataLinkHelper
Dim ConnectionString As String
Dim adoConnection As New ADODB.Connection

' Connect via an open MDM Document
MDMDoc.Open(" [INSTALL_FOLDER]\IBM\SPSS\DataCollection\7\DDL\Data\Data Collection File\museum.mdd", , _
MDMLib.openConstants.oREAD)
ConnectionString = "Provider=mrOleDB.Provider.2;MR Init MDM Document=" & _
DataLinkHelper.CreateDocumentObjectString(MDMDoc)
adoConnection.Open(ConnectionString)

' Connection is ready to use...
Here is an example of the connection string:
Provider=mrOleDB.Provider.2;MR Init MDM Document=mrCommon.MeowMoniker.1:TUVPVwEAAAAA
BAIAAAAAAMAAAAAAAABGAAAAAAUAAACgEwAAxvhjKqYTAADG+GMqAgAAAKAHAADUBwAACgAAADgAJQAHAGwA
cAByAG8AZABkAGUAdgAwADIAcAAuAHMAcABzAHMALgBjAG8AbQAAAAcAMQAwAC4AMQAwAC4AMQAzADQALgA2
ADgAAAAAAAkA//8AABAA//8AAAoA//8AAA4A//8AABEA//8AABIA//8AAAAA
The connection string cannot be reused after the MDM Document has been closed.
Requirements
UNICOM Intelligence Data Model
See also
Connection properties
Getting the connection properties for a connection string
Connecting to case data with and without metadata