Connect to Enterprise Geodatabase (C++)

Created:11/8/1999
Description:

Making a connection to an ArcSDE geodatabase workspace is the foundatation to accessing enterprise data. This sample will show you how to connect to a geodatabase residing on an ArcSDE server.

How to use:
  1. Paste the code into your C++ application.
  2. Call the function from within your application.
//
// 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);
}