No database open via CMI

  • Thread starter Thread starter Mikhail Mintchenkov
  • Start date Start date
M

Mikhail Mintchenkov

Hi all,

I'm trying to use CMI to perform some operations.
Below the VBS code to open and close DB.
But it outputs "No database open"
(CMIEXP otputs ok when I type DBOPEN MY_SERVER ).
Where the difference can be ?

Best Regards,
Mikhail



Dim server
server = "MY_SERVER" 'set the server name

Dim g_oCMI
Set g_oCMI = Wscript.CreateObject( "CMI.CMI") 'Create CMI

Dim nOpenMode
nOpenMode = cmiDBReadOnly

g_oCMI.OpenDB server , nOpenMode 'Open the DB with minimal requirements

If g_oCMI.DBOpenMode = cmiDBNotOpen Then ' If not open..
Wscript.Echo "No database open."
Else
Wscript.Echo "Server : " & g_oCMI.DBServerName
Wscript.Echo "Database : " & g_oCMI.DBName
Wscript.Echo "Generation : " & g_oCMI.DBGeneration
Wscript.Echo "Open mode : " & ValueToString(g_oCMI.DBOpenMode,
cmiDBOpenModeEnum, True)(1)
End If

g_oCMI.CloseDB
 
Mikhail,

You are not taking into consideration the fact that cmi constants are not availalbe through WSH just like that (you have to define
them manually, e.g. define DBModeConsts enum type).

Anyway.. Here is working example for you:

Dim server
server = "your server name" 'set the server name

Dim g_oCMI
Set g_oCMI = Wscript.CreateObject( "CMI.CMI") 'Create CMI

Dim nOpenMode
nOpenMode = 1 ' Note: cmiDBReadImport = 1 or cmiDBExclusive = 2 - will work, cmiDBReadOnly = 0 - won't work.

g_oCMI.OpenDB server, nOpenMode 'Open the DB with minimal requirements

If g_oCMI.DBOpenMode = cmiDBNotOpen Then ' If not open..
Wscript.Echo "No database open."
Else
Wscript.Echo "Server : " & g_oCMI.DBServerName
Wscript.Echo "Database : " & g_oCMI.DBName
Wscript.Echo "Generation : " & g_oCMI.DBGeneration
' removed last line here because of the same cmi constant problem
End If

g_oCMI.CloseDB
 
KM,

Thank you very much.
It seems that it works, but it throw an error:

script.vbs(10, 1) CMIM.MantisDB.1: A database error occurred within the CMI.
For more information see the application event log.

How it can be eliminated?

Best Regards,
M.M.


KM said:
Mikhail,

You are not taking into consideration the fact that cmi constants are not
availalbe through WSH just like that (you have to define
them manually, e.g. define DBModeConsts enum type).

Anyway.. Here is working example for you:

Dim server
server = "your server name" 'set the server name

Dim g_oCMI
Set g_oCMI = Wscript.CreateObject( "CMI.CMI") 'Create CMI

Dim nOpenMode
nOpenMode = 1 ' Note: cmiDBReadImport = 1 or cmiDBExclusive = 2 - will
work, cmiDBReadOnly = 0 - won't work.
 
Mikhail,

In the sample script I sent earlier, did you replace the "your server name" with your dev.machine computer name?

KM
 
KM,

Of course ;-)

But it was switched out ;-) (I was unable to know it while testing the
script)
Now works well!
Thank you!

M.M.


KM said:
Mikhail,

In the sample script I sent earlier, did you replace the "your server
name" with your dev.machine computer name?
 
Back
Top