连接SDE数据库

连接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);
}
posted @ 2012-11-08 21:48  IT.笨笨  阅读(1034)  评论(0编辑  收藏  举报