4

I've set up an Oracle user Schema geodatabase and loaded some data into it. I now want to connect to it programmatically using ArcObjects, the problem is I don't see how. Where can I set the newly created schema name in my connection property set, or how do I change the schema value after I have connected? In ArcCatalog it is done in the Geodatabase connection properties window : enter image description here

The code below works fine connecting to the default SDE schema. What do I have to change to connect to a user geodatabase? I have tried examining IDatabaseConnectionInfo2 and IWorkspaceProperties but I don't see where I can set or change the schema that is connected to.

 public static IWorkspace ConnectToTransactionalVersion(String dbclient, String dbConnProp, String user, String password, String database, String version, String authentication)
    {
        IPropertySet propertySet = new PropertySet();
        propertySet.SetProperty("DBCLIENT", dbclient);
        propertySet.SetProperty("DB_CONNECTION_PROPERTIES", dbConnProp);
        propertySet.SetProperty("DATABASE", database);
        propertySet.SetProperty("USER", user);
        propertySet.SetProperty("PASSWORD", password);
        propertySet.SetProperty("VERSION", version);
        propertySet.SetProperty("AUTHENTICATION_MODE", authentication);
        Type factoryType = Type.GetTypeFromProgID(
            "esriDataSourcesGDB.SdeWorkspaceFactory");
        IWorkspaceFactory workspaceFactory = (IWorkspaceFactory)Activator.CreateInstance
            (factoryType);
        return workspaceFactory.Open(propertySet, 0);
    }

I tried adding "SCHEMA" as a property in propertySet and it gets ignored, I also tried setting the version property to the new user schema default version but it errors with "version not found"

2 Answers 2

2

Create a connection file (sde file) with ArcCatalog.

Solution 1: Use this connection file like in my example (first 7 lines). I think this is not that good, because you have to distribute the sde file, too.

Solution 2: Maybe you can make some kind of ‘reverse engeneering’. In the example below (all lines) you could establish the connection to your workspace by the sde file and read the properties of this file. I hope you will find the missing parameter.

IWorkspaceFactory wsFactory = null;
IFeatureWorkspace featWs = null;
object names = null;
object values = null;
try
{
    wsFactory = new SdeWorkspaceFactoryClass();
    featWs = (IFeatureWorkspace)wsFactory.OpenFromFile(@"D:\Test.sde", 0);

    IWorkspace ws = featWs as IWorkspace;
    if (ws != null)
    {
        IPropertySet props = ws.ConnectionProperties;
        props.GetAllProperties(out names, out values);
    }
}
catch (Exception ex)
{
}
2

Hy, this code is working for me under Java:

 IPropertySet propertySet = new PropertySet();
 propertySet.setProperty("SERVER", "myserver");
 propertySet.setProperty("INSTANCE", "5151:ASSESSOR");
 propertySet.setProperty("DATABASE", "");
 propertySet.setProperty("USER", "myusername");
 propertySet.setProperty("PASSWORD", "mypassword");
 propertySet.setProperty("VERSION", "ASSESSOR.DEFAULT");
 IWorkspaceFactory workspaceFactory = new SdeWorkspaceFactory();
 return (Workspace) workspaceFactory.open(propertySet, 0);

The only special is the INSTANCE and the VERSION which are containing user-schema related informations, in your case assessor.

new UPDATE: Please find here the code for a user-schema geodatabase direct-connection:

  PropertySet propertySet = new PropertySet();
  propertySet.setProperty("INSTANCE", "sde:oracle:XE:DGP_OWNER");
  propertySet.setProperty("USER", "dgp_owner");
  propertySet.setProperty("PASSWORD", "xxxxxxx");
  propertySet.setProperty("VERSION", "DGP_OWNER.DEFAULT");
  workspace = workspaceFactory.open(propertySet, 0);

This code will connect to the user-schema DGP_OWNER geodatabase in the XE-named Oracle database.

3
  • It looks like your code is connecting through an application tier i.e. through an SDE service on port 5151. Is this understanding correct? I'm trying to use direct connect as we don't run the application tier.
    – Dowlers
    Commented Aug 24, 2016 at 17:35
  • If you like to use direct connect you should simply replace the 5151 by the SID of your database defined in your local tnsnames.ora. In my opinion this should work (but is untested!). If not please try "sde:oracle11g:SID:ASSESSOR" for the INSTANCE parameter (assuming you are using Oracle 11 or 12).
    – Propper
    Commented Aug 29, 2016 at 6:46
  • @Propper I've used every combination of parameters for INSTANCE I can think of and no luck. I get either "instance not found in services file" error, or if I use the correct tnsname entry, I get connected to the SDE geodatabase not the assessor geodatabase. What I've tried: "sde:oracle11g:SID:Assessor", "sde:oracle11g:<server>/instance", "<server>/<instance>", "sde:oracle11g:vulcan.world" (vulcan.world is the tnsname.ora entry). If I use the TNS names entry I get connected to SDE.Default, if I use ASSESSOR in any part I get the "instance not found in services file" error
    – Dowlers
    Commented Sep 1, 2016 at 3:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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