This document is archived and information here might be outdated.  Recommended version.


How to connect to an enterprise geodatabase (ArcObjects .NET 10.8 SDK)
ArcObjects Help for .NET developers > ArcObjects Help for .NET developers > Appendix: ArcObjects in Visual C++ > Samples > Geodatabase > Accessing data > How to connect to an enterprise geodatabase

How to connect to an enterprise geodatabase


Making a connection to an ArcSDE geodatabase workspace is the foundation to accessing enterprise data. This sample will show you how to connect to a geodatabase residing on an ArcSDE server. The example code is a function that takes the name of the server, the instance name, user name and password and optional database and version names as strings and returns a workspace.

How to use

  1. Paste the function in your project.
  2. Call the function from your code.
[VCPP]
//
//
// openSDEWorkspace:  create and open the sde workspace based on the provided information
//
HRESULT connectToSDE(BSTR server, BSTR instance, BSTR user, BSTR passwd, BSTR
  database, BSTR version, IWorkspace **outWorkspace)
{
  if (outWorkspace == NULL)
    return E_POINTER;

  // create the property set for the connection parameters
  IPropertySetPtr ipPropertySet;
  ipPropertySet.CreateInstance(CLSID_PropertySet);

  // configure the propertyset
  ipPropertySet->SetProperty(CComBSTR("SERVER"), CComVariant(server));
  ipPropertySet->SetProperty(CComBSTR(L "INSTANCE"), CComVariant(instance));
  ipPropertySet->SetProperty(CComBSTR(L "DATABASE"), CComVariant(database));
  ipPropertySet->SetProperty(CComBSTR(L "USER"), CComVariant(user));
  ipPropertySet->SetProperty(CComBSTR(L "PASSWORD"), CComVariant(passwd));
  ipPropertySet->SetProperty(CComBSTR(L "VERSION"), CComVariant(version));

  // open workspace
  IWorkspaceFactoryPtr ipWorkspaceFactory;
  ipWorkspaceFactory.CreateInstance(CLSID_SdeWorkspaceFactory);
  return ipWorkspaceFactory->Open(ipPropertySet, NULL, outWorkspace);
}






Development licensing Deployment licensing
Engine Developer Kit Engine