C# ArcObjects Oracle Connection string

8793
5
Jump to solution
08-04-2014 09:01 AM
JordanBaumgardner
Occasional Contributor III

Arrrg! I'm having a terrible time translating this connection string, would someone mind taking a stab at it?

Working connection in everything else:

//public string connectString = "SERVER=11.111.11.111;DATABASE=ABCDE;PORT=5121;USER=sde;PASSWORD=password;VERSION=SDE.DEFAULT";

Don't work:

            IPropertySet connectionProps = new PropertySet();

            connectionProps.SetProperty("dbclient", "Oracle11g");

            connectionProps.SetProperty("server", "11.111.11.123");      // Also tried: [11.111.11.123:5121 | 11.111.11.123:5121/ABCDE]

            connectionProps.SetProperty("instance", "5121");                // Also tried [11.111.11.123:5121/ABCDE | 11.111.11.123:5121 | "" ]

            connectionProps.SetProperty("database", "ABCDEF");        // Also tried [ "" | "SDE" ]

            connectionProps.SetProperty("version", "sde.DEFAULT");

            connectionProps.SetProperty("user", "SDE");

            connectionProps.SetProperty("password", "password");

            return workspaceFactory.Open(connectionProps, 0);

I've tried every bloody combination I can think of.

I usually get "Entry for SDE instance not found in services file"

or

"Network I/O error"

or

"SDE not running on server"

Thanks in advance!

0 Kudos
1 Solution

Accepted Solutions
RiyasDeen
Occasional Contributor III

My recommendation would be to establish connection to your DB in arc catalogue, test the connection.

If test succeeds then pick up your .sde file found @

C:\Users\<<user name>>\AppData\Roaming\ESRI\Desktop10.2\ArcCatalog (windows 7)

Below code establishes connection using the sde file and returns a feature class.

public IFeatureClass GetSdeFeatureClass(string featureClassName)

        {

            IFeatureClass featureClass = null;

            IWorkspaceFactory workspaceFactory = null;

            IFeatureWorkspace destinationWorkspace = null;

            try

            {

                workspaceFactory = new SdeWorkspaceFactoryClass();

                destinationWorkspace = (IFeatureWorkspace)workspaceFactory.OpenFromFile(<<Path to your sde file>>, 0);

                featureClass = destinationWorkspace.OpenFeatureClass(featureClassName);

            }

            catch (Exception ex)

            {

                throw ex;

            }

            finally

            {

                DisposeComObjects(workspaceFactory);

                DisposeComObjects(destinationWorkspace);

            }

            return featureClass;

        }

View solution in original post

5 Replies
AdamFeidt
New Contributor II

This worked for me:  FYI...Direct Oracle Connection.

    private IGxDatabase2 pGXdb2;
   
   
                IPropertySet pPropset = default(IPropertySet);
                IWorkspaceName pInWorkspaceName = default(IWorkspaceName);
                string tInProgID = null;

                pPropset = new PropertySet();
                //create a propertyset using specified settings
                var _with3 = pPropset;
                _with3.SetProperty("SERVER", "");
                _with3.SetProperty("INSTANCE", "sde:oracle11g:ABCDEF");
                _with3.SetProperty("DATABASE", "");
                _with3.SetProperty("USER", "sde");
                _with3.SetProperty("PASSWORD", "password");
                _with3.SetProperty("VERSION", "SDE.DEFAULT");

                pGXdb2 = null;

                // Create the source workspace name.
                pInWorkspaceName = new WorkspaceNameClass();
                pInWorkspaceName.ConnectionProperties = pPropset;

                tInProgID = "esriDataSourcesGDB.SdeWorkspaceFactory";
                pInWorkspaceName.WorkspaceFactoryProgID = tInProgID;

                pGXdb2 = new GxDatabaseClass();
                pGXdb2.WorkspaceName = pInWorkspaceName;

                pGXdb2.Connect();

Adam

RiyasDeen
Occasional Contributor III

My recommendation would be to establish connection to your DB in arc catalogue, test the connection.

If test succeeds then pick up your .sde file found @

C:\Users\<<user name>>\AppData\Roaming\ESRI\Desktop10.2\ArcCatalog (windows 7)

Below code establishes connection using the sde file and returns a feature class.

public IFeatureClass GetSdeFeatureClass(string featureClassName)

        {

            IFeatureClass featureClass = null;

            IWorkspaceFactory workspaceFactory = null;

            IFeatureWorkspace destinationWorkspace = null;

            try

            {

                workspaceFactory = new SdeWorkspaceFactoryClass();

                destinationWorkspace = (IFeatureWorkspace)workspaceFactory.OpenFromFile(<<Path to your sde file>>, 0);

                featureClass = destinationWorkspace.OpenFeatureClass(featureClassName);

            }

            catch (Exception ex)

            {

                throw ex;

            }

            finally

            {

                DisposeComObjects(workspaceFactory);

                DisposeComObjects(destinationWorkspace);

            }

            return featureClass;

        }

SusannSchmidt
New Contributor III

I figthed the same war a few months ago and this is working for me:

string sid="orcl_dbname"; // from tnsnames.ora

IPropertySet connectionProps = new PropertySetClass();

connectionProps.SetProperty("SERVER", sid);

connectionProps.SetProperty("SERVERINSTANCE", "sde:oracle11g:/;LOCAL="+sid);

connectionProps.SetProperty("DATABASE", "");

connectionProps.SetProperty("DBCLIENT", "oracle");

connectionProps.SetProperty("db_connection_properties", sid);

connectionProps.SetProperty("AUTHENTICATION_MODE", "DBMS");

connectionProps.SetProperty("USER", user);

connectionProps.SetProperty("PASSWORD", password);

So good luck!

JordanBaumgardner
Occasional Contributor III

Thank you all, I tried Riyas' solution first as it looked the easiest, but I think all of your answers would have solved my issue. Thanks again to all.

0 Kudos
KennethDinsmore
New Contributor II

If you need the same application to connect to Oracle and SQL Server, you can put the property values in your app.config file and read them from the application. The appsettings section would look something like this for an oracle instance with a sid of "orcl":

<add key="SERVER" value="" />
<add key="DBCLIENT" value="oracle" />
<add key="DATABASE" value="" />
<add key="INSTANCE" value="sde:oracle11g:myserver/orcl" />
<!--DBMS or OSA-->
<add key="AUTHENTICATION_MODE" value="DBMS" />
<add key="USER" value="myuser" />
<add key="PASSWORD" value="mypassword" />

<add key="VERSION" value="SDE.DEFAULT" />

While the same appsettings section for SQL Server might look like this:

<add key="SERVER" value="myserver" />
<add key="DBCLIENT" value="SQL Server" />
<add key="DATABASE" value="mysdedatabase" />
<add key="INSTANCE" value="sde:sqlserver:myserver" />
<!--DBMS or OSA-->
<add key="AUTHENTICATION_MODE" value="DBMS" />
<add key="USER" value="myuser" />
<add key="PASSWORD" value="mypassword" />

<add key="VERSION" value="dbo.DEFAULT" />

0 Kudos