Connect to Enterprise Geodatabase (VB)

Created:11/8/1999
Description:

Making a connection to an ArcSDE geodatabase workspace is the foundatation to accessing enterprise data. This sample will show you how to connect to a geodatabase residing on an ArcSDE server.

How to use:
  1. Paste the code into your VB or VBA application.
  2. Call the function from within your application.
''
'' openSDEWorkspace:  create and open the sde workspace based on the provided information
''
Public Function openSDEWorkspace(Server As String, Instance As String, User As String, _
                 Password As String, Optional Database As String = "", _
                 Optional version As String = "SDE.DEFAULT") As IWorkspace
  
  On Error GoTo EH
  Set openSDEWorkspace = Nothing
  
  Dim pPropSet As IPropertySet
  Dim pSdeFact As IWorkspaceFactory
  
  Set pPropSet = New PropertySet
  With pPropSet
    .SetProperty "SERVER", Server
    .SetProperty "INSTANCE", Instance
    .SetProperty "DATABASE", Database
    .SetProperty "USER", User
    .SetProperty "PASSWORD", Password
    .SetProperty "VERSION", version
  End With
  
  Set pSdeFact = New SdeWorkspaceFactory
  Set openSDEWorkspace = pSdeFact.Open(pPropSet, 0)
  Exit Function
EH:
    MsgBox Err.Description, vbInformation, "openSDEWorkspace"
End Function