Exception
-
Hi All I try to create database and table in Access database through this way.
_CatalogPtr m_pCatalog = NULL;
CString con="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\test.mdb;Jet OLEDB:Engine Type=5";
HRESULT hr = S_OK;
try
{TESTHR(hr = m\_pCatalog.CreateInstance(\_\_uuidof (Catalog))); m\_pCatalog->Create((\_bstr\_t)con);
}
catch(_com_error pCE)
{
}.
.//create table
.
.
m_pCatalog->Release();
CoUninitialize();Database name(test.mdb) read from list(list have more than one database name).I use here m_pCatalog->Release(); Now when i select different database name that time this line TESTHR(hr = m_pCatalog.CreateInstance(__uuidof (Catalog))); through exception. Exception show
HRESULT CreateInstance(const CLSID& rclsid, IUnknown* pOuter = NULL, DWORD dwClsContext = CLSCTX_ALL) throw()
{
HRESULT hr;**point out this line** \_Release();//this line if (dwClsContext & (CLSCTX\_LOCAL\_SERVER | CLSCTX\_REMOTE\_SERVER)) { IUnknown\* pIUnknown; hr = CoCreateInstance(rclsid, pOuter, dwClsContext, \_\_uuidof(IUnknown), reinterpret\_cast<void\*\*>(&pIUnknown)); if (SUCCEEDED(hr)) { hr = OleRun(pIUnknown); if (SUCCEEDED(hr)) { hr = pIUnknown->QueryInterface(GetIID(), reinterpret\_cast<void\*\*>(&m\_pInterface)); } pIUnknown->Release(); } } else { hr = CoCreateInstance(rclsid, pOuter, dwClsContext, GetIID(), reinterpret\_cast<void\*\*>(&m\_pInterface)); } if (FAILED(hr)) { // just in case refcount = 0 and dtor gets called m\_pInterface = NULL; } return hr; }
I use m_pCatalog->Release() because once i create database and table then i try to free particular database. Please help me
-
Hi All I try to create database and table in Access database through this way.
_CatalogPtr m_pCatalog = NULL;
CString con="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\test.mdb;Jet OLEDB:Engine Type=5";
HRESULT hr = S_OK;
try
{TESTHR(hr = m\_pCatalog.CreateInstance(\_\_uuidof (Catalog))); m\_pCatalog->Create((\_bstr\_t)con);
}
catch(_com_error pCE)
{
}.
.//create table
.
.
m_pCatalog->Release();
CoUninitialize();Database name(test.mdb) read from list(list have more than one database name).I use here m_pCatalog->Release(); Now when i select different database name that time this line TESTHR(hr = m_pCatalog.CreateInstance(__uuidof (Catalog))); through exception. Exception show
HRESULT CreateInstance(const CLSID& rclsid, IUnknown* pOuter = NULL, DWORD dwClsContext = CLSCTX_ALL) throw()
{
HRESULT hr;**point out this line** \_Release();//this line if (dwClsContext & (CLSCTX\_LOCAL\_SERVER | CLSCTX\_REMOTE\_SERVER)) { IUnknown\* pIUnknown; hr = CoCreateInstance(rclsid, pOuter, dwClsContext, \_\_uuidof(IUnknown), reinterpret\_cast<void\*\*>(&pIUnknown)); if (SUCCEEDED(hr)) { hr = OleRun(pIUnknown); if (SUCCEEDED(hr)) { hr = pIUnknown->QueryInterface(GetIID(), reinterpret\_cast<void\*\*>(&m\_pInterface)); } pIUnknown->Release(); } } else { hr = CoCreateInstance(rclsid, pOuter, dwClsContext, GetIID(), reinterpret\_cast<void\*\*>(&m\_pInterface)); } if (FAILED(hr)) { // just in case refcount = 0 and dtor gets called m\_pInterface = NULL; } return hr; }
I use m_pCatalog->Release() because once i create database and table then i try to free particular database. Please help me
What was the exception message? :)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
What was the exception message? :)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
Thanks for reply
Unhandled exception at 0x004098ec in test.exe: 0xC0000005: Access violation reading location 0x00000008
Did you call
Release
,CoUninitialize
, and thenCreateInstance
aqain? :)If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
Did you call
Release
,CoUninitialize
, and thenCreateInstance
aqain? :)If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles]