Solved! Go to Solution.
private static void connectToSQLServer(){ try { IPropertySet propertySet = new PropertySet(); propertySet.setProperty("SERVER", "server_name"); propertySet.setProperty("SERVERINSTANCE", "server_name"); // Or server_name\\server_instance_name if SQL named instance propertySet.setProperty("DATABASE", "database_name"); propertySet.setProperty("DBCLIENT", "SQLServer"); propertySet.setProperty("USER", "user_name"); propertySet.setProperty("PASSWORD", "user_password"); //propertySet.setProperty("AUTHENTICATION_MODE", "DBMS"); // Optional. DBMS is default //propertySet.setProperty("AUTHENTICATION_MODE", "OSA"); // Required if using Operating Sytem Authentication IWorkspaceFactory workspaceFactory = new SqlWorkspaceFactory(); // Note: using SqlWorkspaceFactory IWorkspace workspace = new Workspace(workspaceFactory.open(propertySet, 0)); IEnumDatasetName dsFeatureClassNames = workspace.getDatasetNames(esriDatasetType.esriDTAny); IDatasetName fcName = dsFeatureClassNames.next(); while (fcName != null){ System.out.println(fcName.getName()); fcName = dsFeatureClassNames.next(); } } catch (AutomationException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
private static void connectToSDE(){ try { IPropertySet propertySet = new PropertySet(); propertySet.setProperty("SERVER", "server_name"); propertySet.setProperty("INSTANCE", "sde:sqlserver:SERVER_NAME"); propertySet.setProperty("DATABASE", "database_name"); propertySet.setProperty("USER", "user_name"); propertySet.setProperty("PASSWORD", "user_password"); propertySet.setProperty("VERSION", "sde.DEFAULT"); // Create a SdeWorkspaceFactory and open it IWorkspaceFactory sdeworkspaceFactory = new SdeWorkspaceFactory(); // Note: using SdeWorkspaceFactory IWorkspace workspace = new Workspace(sdeworkspaceFactory.open(propertySet, 0)); IEnumDatasetName dsFeatureClassNames = workspace.getDatasetNames(esriDatasetType.esriDTAny); IDatasetName fcName = dsFeatureClassNames.next(); while (fcName != null){ System.out.println(fcName.getName()); fcName = dsFeatureClassNames.next(); } } catch (AutomationException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
// Create a propertySet that contains the connection information to ArcSDE // In ArcCatalog, the first three values are: server, service, database in the connection properties of the sde connection. IPropertySet propertySet = new PropertySet(); propertySet.setProperty("SERVER", "servername"); propertySet.setProperty("INSTANCE", "sde:sqlserver:SERVERNAME"); propertySet.setProperty("DATABASE", "databasename"); propertySet.setProperty("USER", "sde"); propertySet.setProperty("PASSWORD", "sdepassword"); propertySet.setProperty("VERSION", "sde.DEFAULT"); // Create a SdeWorkspaceFactory and open it IWorkspaceFactory sdeworkspaceFactory = new SdeWorkspaceFactory(); IWorkspace workspace = new Workspace(sdeworkspaceFactory.open(propertySet, 0));
Connecting to a SQL workspace
Connecting to a SQL workspace involves creating a SqlWorkspaceFactory and using one of the IWorkspaceFactory or IWorkspaceFactory2 Open methods to provide the workspace factory with connection properties.
The following code sample shows how to connect to an Oracle 11g instance using the IWorkspaceFactory.Open method:
// Create the workspace factory. Type factoryType = Type.GetTypeFromProgID("esriDataSourcesGDB.SqlWorkspaceFactory");
IWorkspaceFactory workspaceFactory = (IWorkspaceFactory)Activator.CreateInstance (factoryType);
// Create the connection properties. IPropertySet connectionProps = new PropertySetClass();
connectionProps.SetProperty("dbclient", "Oracle11g");
connectionProps.SetProperty("serverinstance", "MyServer");
connectionProps.SetProperty("authentication_mode", "DBMS");
connectionProps.SetProperty("user", "MyLogin");
connectionProps.SetProperty("password", "MyPassword");
// Open the workspace. IWorkspace workspace = workspaceFactory.Open(connectionProps, 0);
I was able to use your sample with server name where you supplied IP address. Maybe you need to supply the fully qualified name for your SERVERINSTANCE ?
server.domain_name maybe?