3

I try to retrive the connected users from an entreprise geodatabase using ArcObjects .

first I tried to cast My workspace to IDatabaseConnectionInfo3 but it throws

ClassCastException

IWorkspace workspace = sdeWorkspaceInstance();
IDatabaseConnectionInfo3 databaeseConnectinfo = (IDatabaseConnectionInfo3) workspace;
IEnumUserInfo listUserInfo = databaeseConnectinfo.getConnectedUsers();

Any idea how to use the IDatabaseConnectionInfo3 interface ?

  • try IDatabaseConnectionInfo instead of IDatabaseConnectionInfo3. Make sure your sdeWorkspace is really sde and not e.g. FGDB – Farid Cheraghi Sep 29 '15 at 11:20
  • I dont need to use IDatabaseConnectionInfo because , what I need is retriving a list of users not just the admin user IDatabaseConnectionInfo has the getConnectedUser(); which return a "String" instead of getConnectedUsers(); – Springer F Sep 29 '15 at 12:59
  • what does IWorkspace.Type returns for your workspace? and Is your workspace an admin workspace? – Farid Cheraghi Sep 29 '15 at 13:29
  • what do you mean by "is your workspace an admin workspace ? If you mean that I access my sde workspace by adminGDD user : yes I'm using an sde entreprise database . and I create the workspace using IWorkspaceFactory sdeFactory; sdeFactory= new SdeWorkspaceFactory(); IPropertySet propertySet = new PropertySet(); propertySet.setProperty("SERVER", "10.5.28.143"); all others info...... propertySet.setProperty("VERSION", "SDE.DEFAULT"); return (IWorkspace) pSdeFact.open(propertySet, 0); – Springer F Sep 29 '15 at 13:43
2

The JavaDoc does not state that Sde4Workspace implements IDatabaseConnectionInfo3 -- It only asserts IDatabaseConnectionInfo, which is a superinterface. Therefore the cast should fail (which it does).

If you want to ask Esri why the connection interface doesn't support server info queries, you would need to contact Tech Support, but I suspect it has to do with the difference between the underlying objects -- an Sde4Workspace is essentially a wrapper around SE_CONNECTION (from the 'C' API), while the list of connected users in an instance is a wrapper around SE_instance_get_users (which is a poll of the now deprecated application server).

You could certainly use an Sde4Workspace to fashion a SQL query of the connected users, though this would differ slightly by RDBMS.

1

An SDE workspace should implement that interface, unless it's an Sde3Workspace object. But to be honest, I don't know the difference between Sde3Workspace and Sde4Workspace.

As with all ArcObjects enumerators, you need to call Reset() first, and then loop over the results using Next(). Note that ConnectedUsers may throw an exception if you do not have permission to see the connected users.

Unfortunately I don't know how to use the Java ArcObjects SDK, but I guess it should be very similar to C#, so here's an example:

private void GetConnectedUsers(IWorkspace workspace)
{
    var connectionInfo = workspace as IDatabaseConnectionInfo3;
    if (connectionInfo == null) return; // Other types of workspace, e.g. fgdb

    IEnumUserInfo listUserInfo;
    try
    {
        listUserInfo = connectionInfo.ConnectedUsers;
    }
    catch (Exception ex)
    {
        // May not have permission to see connected users
        Debug.WriteLine(ex.Message);
        return;
    }

    listUserInfo.Reset();

    IUserInfo userInfo;
    while ((userInfo = listUserInfo.Next()) != null)
    {
        Debug.WriteLine(userInfo.Name);
    }
}
  • Thnx , but really I dont understand I just wrote the same as described in your C# code. 'code'var connectionInfo = workspace as IDatabaseConnectionInfo3;'code' in java : 'IDatabaseConnectionInfo3 databaeseConnectinfo = (IDatabaseConnectionInfo3) worspace;' and it throws the :'java.lang.ClassCastException: com.esri.arcgis.geodatabase.Workspace cannot be cast to com.esri.arcgis.geodatabase.IDatabaseConnectionInfo3' i'm so Confused ! – Springer F Sep 29 '15 at 13:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.