This sample script creates a new English Query model using the Authoring object model. This script:
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. CheckForErrorsEQModel.FetchDatabaseStructure adoConn, szEqmID 'Import the database schema. CheckForErrorsConst EQOBJMODULE = 10 'This constant matches constant defined in the object model. EQModel.AutoModel EQOBJMODULE, szEqmID, szEqmID 'Project wizard creates entities and relationships. CheckForErrorsEQModel.SaveModule szEqmID, szEqm'Save the .eqm file. CheckForErrorsEQModel.SaveProjectFile szEqp 'Save the .eqp file. CheckForErrorsEQModel.Build szEqd, adoConn 'Build the project to make an .eqd file. CheckForErrorsSub CheckForErrors()'Check Visual Basic Err object to see whether the method call failed. If err.Number <> 0 ThenMsgBox ("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 - 1Select Case colErrors(i).Severity Case EqSevInfoszMsg = szMsg + "Hint: " & colErrors(i).Text + Chr(10)Case EqSevWarningszMsg = szMsg + "Warning: " & colErrors(i).Text + Chr(10)Case EqSevErrorszMsg = szMsg + "Error: " & colErrors(i).Text + Chr(10) End SelectNext If szMsg <> "" ThenMsgBox (szMsg)End IfEnd Sub