There are several ways to connect to a geodatabase:
1. This is the old, obsolete way to connect to gdb using .NET Framework:
Public Shared Function FileGdbWorkspaceFromPath(ByVal Path As String) As IWorkspace
Dim FileGDBWorkspaceFactory As New FileGDBWorkspaceFactoryClass()
Return FileGDBWorkspaceFactory.OpenFromFile(Path, 0I)
End Function
2. This one is the new, preferred, Activator based connection:
Public Shared Function FileGdbWorkspaceFromPath(ByVal Path As String) As IWorkspace
Const ProgID As String = "esriDataSourcesGDB.FileGDBWorkspaceFactory"
Dim factoryType As Type = Type.GetTypeFromProgID(ProgID)
Dim workspaceFactory As IWorkspaceFactory = _
DirectCast(Activator.CreateInstance(factoryType), IWorkspaceFactory)
Return workspaceFactory.OpenFromFile(Path, 0I)
End Function
3. But what about this one (below)? It looks like the Activator based connection. The workspace object was reached with the same ProgID.
Public Function FileGdbWorkspaceFromPath(ByVal Path As String) As IWorkspace
Const ProgID As String = "esriDataSourcesGDB.FileGDBWorkspaceFactory"
Dim WpName As New WorkspaceNameClass() With
{.WorkspaceFactoryProgID = ProgID, .PathName = Path}
Return DirectCast(WpName.Open(), IWorkspace)
End Function
So what’s the difference between the “WorkspaceName” and the “Activator” based connections?
Ákos Halmai