--- title: "Catalog ActiveConnection Property Example (VC++) | Microsoft Docs" ms.prod: sql ms.prod_service: connectivity ms.technology: connectivity ms.custom: "" ms.date: "01/19/2017" ms.reviewer: "" ms.topic: conceptual dev_langs: - "C++" helpviewer_keywords: - "ActiveConnection property [ADOX], VC++ example" ms.assetid: 518905a9-6044-4194-af6c-84952d95939d author: MightyPen ms.author: genemi --- # Catalog ActiveConnection Property Example (VC++) Setting the [ActiveConnection](../../../ado/reference/adox-api/activeconnection-property-adox.md) property to a valid, open connection "opens" the catalog. From an open catalog, you can access the schema objects contained within that catalog. ``` // CatalogActiveConnectionCpp.cpp // compile with: /EHsc #import "msado15.dll" rename("EOF", "EndOfFile") #import "msadox.dll" no_namespace #include "iostream" using namespace std; // Function declarations inline void TESTHR(HRESULT x) {if FAILED(x) _com_issue_error(x);}; void OpenConnectionX(); void OpenConnectionWithStringX(); int main() { if ( FAILED( ::CoInitialize(NULL) ) ) return -1; OpenConnectionX(); OpenConnectionWithStringX(); ::CoUninitialize(); } void OpenConnectionX() { HRESULT hr = S_OK; // Define ADOX object pointers, initialize pointers. These are in ADODB namespace. _CatalogPtr m_pCatalog = NULL; // Define ADODB object pointers ADODB::_ConnectionPtr m_pCnn = NULL; // Define string variables. _bstr_t strcnn("Provider='Microsoft.JET.OLEDB.4.0';Data source = 'c:\\Northwind.mdb';"); try { TESTHR(hr = m_pCnn.CreateInstance(__uuidof(ADODB::Connection))); TESTHR(hr = m_pCatalog.CreateInstance(__uuidof (Catalog))); m_pCnn->Open(strcnn, "", "", NULL); m_pCatalog->PutActiveConnection(_variant_t((IDispatch *) m_pCnn)); _variant_t vIndex = (short) 0; cout<Tables->GetItem(vIndex)->Type<State == 1) m_pCnn->Close(); } void OpenConnectionWithStringX() { HRESULT hr = S_OK; // Define ADOX object pointers, initialize pointers. These are in ADODB namespace. _CatalogPtr m_pCatalog = NULL; // Define string variables. _bstr_t strcnn("Provider='Microsoft.JET.OLEDB.4.0';Data source = 'c:\\Northwind.mdb';"); try { TESTHR(hr = m_pCatalog.CreateInstance(__uuidof (Catalog))); m_pCatalog->PutActiveConnection(strcnn); _variant_t vIndex = (short) 0; cout<Tables->GetItem(vIndex)->Type<