Tip

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

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

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:

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.