Desktop User Guides > Professional > Troubleshooting > Data Management troubleshooting > Programmer's FAQs
 
Programmer's FAQs
Does the fact that WinDMSRun was developed in Visual Basic .NET mean that you cannot use the Data Management Object Model in Visual Basic?
The Data Management Object Model (DMOM) is a .NET assembly. However, all of the objects within it are exposed as COM objects and can therefore be accessed from Visual Basic in the normal way.
To show you how easy it is, here is some Visual Basic code that runs a DMS file:
Dim j As New Job

j.Load ("C:\Samples\MyFirstTransfer.dms")
j.Run
Here is another Visual Basic example that sets up a DMS file and runs it:
Dim job As New SPSSMR_Data_Transformations.job

' Set up and add input data source
Dim dsin As New SPSSMR_Data_Datasource.DataSource
dsin.Name = "Input"
dsin.SetConnectionString ( _
  "Provider=mrOleDB.Provider.2 ; " + _
  "Data Source=mrDataFileDsc ;" + _
  "Location=museum.ddf;" + _
  "Initial Catalog=museum.mdd;")
  dsin.QueryString = "SELECT * FROM VDATA"
job.InputDataSources.Add dsin

' Set up and add output data source
Dim dsout As New DataSource
dsout.Name = "Output"
dsout.SetConnectionString ( _
  "Provider=mrOleDB.Provider.2 ; " + _
  "Data Source=mrDataFileDsc ;" + _
  "Location=VBTest.ddf;")
dsout.MetaDataOutputName = "VBTest.mdd"

job.OutputDataSources.Add dsout
' Run the job
job.Run
job.Save ("VBTest.dms")
Before you can run this code in Visual Basic, you need to add SPSS MR Data Manager Object Model for Transformations and SPSS MR Data Source to the Visual Basic project references.
Here is some roughly equivalent Visual Basic .NET code:
Imports SPSSMR.Data
Imports SPSSMR.Data.Transformations

Module Module1
  Private Sub OnNextCaseEventHandler(ByVal sender As         System.Object, ByVal e As System.EventArgs)
    Console.WriteLine("Next case !")
  End Sub

  Sub Main()
    Dim job As New Job()
    ' Set up and add input data source
    Dim dsin As New DataSource()
    dsin.Name = "Input"
    dsin.SetConnectionString ( _
      "Provider=mrOleDB.Provider.2 ; " + _
      "Data Source=mrDataFileDsc ;" + _
      "Location=museum.ddf ;" + _
      "Initial Catalog=museum.mdd ;")
    dsin.QueryString = "SELECT * FROM VDATA"
      job.InputDataSources.Add(dsin)
    ' Set up and add output data source
    Dim dsout As New DataSource()
      dsout.Name = "Output"
      dsout.SetConnectionString ( _
        "Provider=mrOleDB.Provider.2 ; " + _
        "Data Source=mrDataFileDsc ;" + _
        "Location=MuseumOut.ddf ;")
      dsout.MetaDataOutputName = "MuseumOut.mdd"
      job.OutputDataSources.Add(dsout)
     ' Add event handler for NextCase
    AddHandler job.NextCase, AddressOf OnNextCaseEventHandler
    ' Run the job
    job.Run()
  End Sub
End Module
Is there any way of executing a DMS file from within an ASP.NET page? For example, I want to create a web page where you can select the UNICOM Intelligence Interviewer - Server Admin project and an output format (such as Quantum or IBM SPSS Statistics) and then the page generates and executes a DMS file.
DMS Runner is a very thin client on top of the Data Management Object Model (DMOM), which contains all of the data management functionality. The most elegant way to program against DMOM is through managed code in Visual Studio .NET (C# or Visual Basic .NET). So ASP.NET is perfect.
The UNICOM Intelligence Developer Documentation Library comes with the Visual Basic .NET source code of the WinDMSRun sample application. If you look at this code, you will see an example of programming using DMOM. See WinDMSRun as programmer’s reference for more information.
How do you destroy the Job object in Visual Basic? The Job.Close method appears to close the job without destroying the Visual Basic Variable.
You can destroy the Job object in the same way as you can destroy any COM variable in Visual Basic using the following code:
Set MyJob = Nothing
This will decrease the reference count on the COM object and thus destroy the object if it is the only reference left.
Is there a method for removing the input data sources? I am working in Visual Basic and have created a subroutine that populates the input and output data sources. However, if I change the input or output data sources and call it again, I get an error saying that I already have these in the job. I get this error even if I call the DataSource.Close method.
In UNICOM Intelligence Professional 2.0 and later, DMOM has a DataSources.Remove method, which you can use to remove the input data source.
Previously, you had to set the Job object to Nothing before calling the subroutine again or find another solution. For example, WinDMSRun copies a “design” Job object into a “Run” Job object and then runs that and destroys it. The relevant code is in ProgressForm.vb. If you do not have Visual Basic .NET, you can examine the code in a text editor. Although the Visual Basic .NET syntax is different from Visual Basic, you should be able to follow the logic.
When programming with DMOM, I consistently get a threading error (Wrong Apartment Model) when attempting to create and execute a job. Why is this?
DMOM requires a single-threaded apartment (STA) threading model. In an ASP .NET environment you can use the following code to run the Web application in an STA thread pool:
<%@ Page ASPCompat="true" %>
The routing script in the output MDD file is changed after exporting. Why is this?
During an export, DMOM removes all fields, reintroduces the required fields, and adds the fields to the Paper routing (only when the fields are appropriate in the Paper routing). This can result in duplicate items being added to the Paper routing. In DMOM, the generated MDD is not useful for surveys. As such, changes to the routing script are irrelevant.
See also
Data Management troubleshooting