Connect to a Personal Geodatabase (C++)

Created:11/8/1999
Description:

Making a connection to a personal geodatabase workspace is the foundatation to accessing data. This sample will show you how to connect to a geodatabase stored in an .mdb file.

How to use:
  1. Paste the code into your C++ application.
  2. Call the function from within your application.
//
// openAccessWorkspace:  connect to a personal geodatabase
// connString should be full path to the access database with .mdb extension
//    example "c:\temp\geodata.mdb"
//
HRESULT openAccessWorkspace(BSTR connString, IWorkspace ** outWorkspace)
{

	HRESULT hr;
	CComPtr<IWorkspaceFactory> ipWorkspaceFactory;
	ipWorkspaceFactory.CoCreateInstance(CLSID_AccessWorkspaceFactory);

	return ipWorkspaceFactory->OpenFromFile(connString, NULL, outWorkspace);
}