Export (0) Print
Expand All

Authoring Sample Script

SQL Server 2000

This sample script creates a new English Query model using the Authoring object model. This script:

  • Loads the schema from the database.

  • Runs the project wizard and uses the AutoModel method to create entities and relationships.

  • Saves the project and then builds it into an English Query Domain (.eqd) file.

You must have a system data source name (DSN) that points to a Northwind database, or alternately, you can specify any database from which you want to create a model. You can copy this sample code and paste it directly into a Microsoft® Visual Basic® Scripting Edition (VBScript) file:

Dim adoConn, szEqmID, szEqm, szEqp, szEqd, szPath, szDatabase
szPath = "c:\temp\Northwind"         'Specify a location to store the files that are created on your local computer.This path must already exist. 
szDatabase = "Northwind"         'Specify a system DSN on your local computer.

Public EQModel
On Error Resume Next
Set EQModel = CreateObject("MSEQ.Model")

'Derive all necessary parameters. ...
szEqp = szPath + "\" + szDatabase + ".eqp"
szEqmID = szDatabase + ".eqm"
szEqm = Left(szEqp, Len(szEqp) - 1) + "m"
szEqd = Left(szEqp, Len(szEqp) - 1) + "d"
Set adoConn = CreateObject("ADODB.Connection")
adoConn.Open (szDatabase)         'Looks for a system DSN.

EQModel.FetchDatabaseStructure adoConn, szEqmID         'Import the database schema.

Const EQOBJMODULE = 10         'This constant matches constant defined in the object model.
EQModel.AutoModel EQOBJMODULE, szEqmID, szEqmID         'Project wizard creates entities and relationships.

EQModel.SaveModule szEqmID, szEqm         'Save the .eqm file.

EQModel.SaveProjectFile szEqp         'Save the .eqp file.

EQModel.Build szEqd, adoConn         'Build the project to make an .eqd file.

Sub CheckForErrors()
'Check Visual Basic Err object to see whether the method call failed.
If err.Number <> 0 Then
MsgBox ("OM Method called failed: " & err.Description)
WScript.Quit (1)
End If

'Check the EQError object to see whether EQ errors, warnings, or hints are generated.
Dim EqSevInfo, EqSevWarning, EqSevError, colErrors, szMsg
EqSevInfo = 0: EqSevWarning = 1: EqSevError = 2: szMsg = ""
'Report only the Warnings and Errors, skip the Info hints.
Set colErrors = EQModel.Errors
For i = 0 To colErrors.Count - 1
Select Case colErrors(i).Severity
   Case EqSevInfo
      szMsg = szMsg + "Hint: " & colErrors(i).Text + Chr(10)
   Case EqSevWarning
      szMsg = szMsg + "Warning: " & colErrors(i).Text + Chr(10)
   Case EqSevError
      szMsg = szMsg + "Error: " & colErrors(i).Text + Chr(10)
End Select
If szMsg <> "" Then
MsgBox (szMsg)
End If
End Sub

© 2014 Microsoft