Get Database Server Name

Created:6/29/2001
Description:

The function below gets the name of the geodatabase server storing a given object or feature.

If the object or feature belongs to a shapefile or coverage, or is from a Geography Network, or OLE DB layer, a null string is returned, since a server name is not necessarily appropriate in those cases.


How to use:
  1. Paste the function into your VB or VBA application.
  2. Call the function from your application. Anything that implements IObject can be passed in, for example a feature.
Public Function ServerName(pObject As IObject) As String
  ' Get the workspace of the object
  Dim pObjectClass As IObjectClass
  Dim pDataset As IDataset
  Dim pWorkspace As IWorkspace
  Set pObjectClass = pObject.Class
  Set pDataset = pObjectClass
  Set pWorkspace = pDataset.Workspace
  
  ' Look for SERVER connection property - dont access it directly since
  ' that would give an error for IMS and OLE DB layers
  Dim sPropNames As Variant
  Dim vPropValues As Variant
  Dim i As Long
  pWorkspace.ConnectionProperties.GetAllProperties sPropNames, vPropValues
  For i = LBound(sPropNames) To UBound(sPropNames)
     If UCase(sPropNames(i)) = "SERVER" Then
       ServerName = vPropValues(i)
       Exit For
     End If
  Next i
End Function