|
连接SDE数据库
void OnTestConnect()
{
// TODO: Add your control notification handler code here
UpdateData();
CGenericClass m采用GenericFun;
IWorkspacePtr ipWS;
m采用GenericFun.connectToSDE(m采用strServer,m采用strService,m采用strUser,m采用strPassword,m采用strDatabase,m采用strConnectVersion,&ipWS);
if(ipWS!=NULL)
{
AfxMessageBox("Test connection successful");
}
else
{
AfxMessageBox(m采用GenericFun.GetErrorDescription());
}
}
// openSDEWorkspace: create and open the sde workspace based on the provided information
//
HRESULT CGenericClass::connectToSDE(CString server,
CString instance,
CString user,
CString passwd,
CString database,
CString version,
IWorkspace ** outWorkspace)
{
if (outWorkspace == NULL)
return E采用POINTER;
// create the property set for the connection parameters
IPropertySetPtr ipPropertySet;
ipPropertySet.CreateInstance(CLSID采用PropertySet);
// open workspace
IWorkspaceFactoryPtr ipWorkspaceFactory;
// configure the propertyset
if(TRUE)//SQL
{
ipWorkspaceFactory.CreateInstance(CLSID采用SdeWorkspaceFactory);
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));
}
return ipWorkspaceFactory->Open(ipPropertySet, NULL, outWorkspace);
} |
|