Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Exception

Exception

Scheduled Pinned Locked Moved C / C++ / MFC
databasehelpannouncement
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    MsmVc
    wrote on last edited by
    #1

    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

    CPalliniC 1 Reply Last reply
    0
    • M MsmVc

      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

      CPalliniC Offline
      CPalliniC Offline
      CPallini
      wrote on last edited by
      #2

      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]

      In testa che avete, signor di Ceprano?

      M 1 Reply Last reply
      0
      • CPalliniC CPallini

        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]

        M Offline
        M Offline
        MsmVc
        wrote on last edited by
        #3

        Thanks for reply

        Unhandled exception at 0x004098ec in test.exe: 0xC0000005: Access violation reading location 0x00000008

        CPalliniC 1 Reply Last reply
        0
        • M MsmVc

          Thanks for reply

          Unhandled exception at 0x004098ec in test.exe: 0xC0000005: Access violation reading location 0x00000008

          CPalliniC Offline
          CPalliniC Offline
          CPallini
          wrote on last edited by
          #4

          Did you call Release, CoUninitialize, and then CreateInstance 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]

          In testa che avete, signor di Ceprano?

          M 1 Reply Last reply
          0
          • CPalliniC CPallini

            Did you call Release, CoUninitialize, and then CreateInstance 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]

            M Offline
            M Offline
            MsmVc
            wrote on last edited by
            #5

            yes you are right..

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups