This agent retrieves and displays the ID of the current database using Notes
API functions. Simply copy this agent into the required
database and run it. The database ID will be displayed in a message box.
The database ID is returned in a TIMEDATE structure and represents the creation
time/date of the specified database.
Given that the value is not GMT normalised and its base unit of storage is 10
milli-second intervals,
this ID can be reliably used as a unique world-wide identifier of a particular
copy or replica of a database.
Option Public
Option Explicit
%INCLUDE "lsconst.lss"
%REM
%END REM
'Declare Types and Functions
Type dbIdType
innards (0 To 1) As Long
End Type
Declare Function OSPathNetConstruct Lib"nnotes" (Byval sPortName As String,
Byval sServerName As String, Byval sFileName As String, Byval sPathName As
String) As Integer
Declare Function NSFDbOpen Lib "nnotes" (Byval sPathName As String, hDB As
Long)As Integer
Declare Function NSFDbClose Lib "nnotes" (Byval hDB As Long) As Integer
Declare Function NSFDbIDGet Lib "nnotes" (Byval hDB As Long, DbID As dbidtype)
As Integer
Sub Initialize
'Declare variables
Dim Nsession As NotesSession
Dim hDB As Long
Dim DBId As DbIDType
Dim sPortName As String * 64
Dim sServerName As String * 256
Dim sFileName As String * 256
Dim sPathName As String * 256
Dim iIndex As Integer
Dim sHexGMT As String
Dim sHexDST As String
Dim sDbId As String
'Get session
Set Nsession = New NotesSession
'Store server and database file name
sServerName = Nsession.CurrentDatabase.Server & Chr(0)
sFileName=Nsession.CurrentDatabase.FilePath & Chr(0)
'Construct path
Call OSPathNetConstruct (sPortName, sServerName, sFileName, sPathName)
'Open database
Call NSFDBOpen( sPathName, hDb )
'Bail if couldn't get handle
If hDb <= 0 Then
Messagebox "Could not get API handle to database " + sPathName, MB_OK
+ MB_ICONSTOP, "No Db Handle"
Exit Sub
End If
'The database ID is returned in a TIMEDATE structure and represents the
creation time/date of the specified database.
'Given that the value is not GMT normalised and its base unit of storage is 10
milli-second intervals,
'this ID can be reliably used as a unique world-wide identifier of a particular
copy or replica of a database.
'Get database ID and close database
Call NSFDBIDGet(hDb,DBId)
Call NSFDBClose(hDb)
'Convert DbId to hex string
sHexGMT = Hex( DbId.innards(1) )
sHexDST = Hex( DbId.innards(0) )
'Pad with leading zeros
For iIndex = 1 To ( 8 - Len(sHexGMT) )
sHexGMT = "0" + sHexGMT
Next
For iIndex = 1 To ( 8 - Len(sHexDST) )
sHexDST = "0" + sHexDST
Next
'Assemble ID
sDbId = sHexGMT + sHexDST
'Display db Id
Messagebox "Database ID : " + sDbId, MB_OK + MB_ICONINFORMATION, sPathName
End Sub
This was first published in November 2000