Retrieve And Display The Id Of The Current Database Using Notes Api Functions

'Get Database ID:

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

Dig deeper on Domino Resources - Part 7

0 comments

Oldest 

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

SearchWinIT

Search400

  • iSeries tutorials

    Search400.com's tutorials provide in-depth information on the iSeries. Our iSeries tutorials address areas you need to know about...

  • V6R1 upgrade planning checklist

    When upgrading to V6R1, make sure your software will be supported, your programs will function and the correct PTFs have been ...

  • Connecting multiple iSeries systems through DDM

    Working with databases over multiple iSeries systems can be simple when remotely connecting logical partitions with distributed ...

SearchEnterpriseLinux

SearchVirtualDataCentre.co.uk

Close