CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    May 1999
    Posts
    8

    Worker threads and CDaoDatabase

    I have an application in which my class runs a database
    analysis. One of the my class members is a CDaoDatabase
    object. In my analysis method I retrieve the active
    database name as follows:

    CString dbPath = m_db.GetName();

    My problem: When I run this analysis method from the
    main thread everything works just fine. But, when I
    run it in a worker thread (which is what I want to do!)
    I get an exception:

    DAO350.DLL: 0xC0000005: Access Violation

    I have traced the code in the debugger, and all the
    CDaoDatabase members are EXACTLY the same whether in the
    main thread or a worker thread. Anyone have any ideas on
    why the CDaoDatabase::GetName() method fails when called
    in the worker thread?

    Below is the code from ..\Vc\mfc\src\Daocore.cpp. I have
    indicated the line of code which fails.

    Any enlightenment would be greatly appreciated!!

    Eric

    =========================================================

    CString CDaoDatabase::GetName()
    {
    ASSERT_VALID(this);
    ASSERT(IsOpen());
    ASSERT(m_pDAODatabase != NULL);

    COleVariant var;
    //<< Blows up on the following statement >>
    DAO_CHECK(m_pDAODatabase->get_Name(&V_BSTR(&var)));
    var.vt = VT_BSTR;
    return V_BSTRT(&var);
    }




    Eric

  2. #2
    Join Date
    May 1999
    Posts
    6

    Re: Worker threads and CDaoDatabase

    Hi!

    As long as I remember, DAO components are not thread-safe. This means that if you have a pointer to such an interface and you use it in the same time (from some threads), you'll get the exception you mentioned.
    Hope it works!


  3. #3
    Join Date
    May 1999
    Posts
    8

    Re: Worker threads and CDaoDatabase

    After posting my original message I found some info here about
    DAO and threads. This is my first foray into both DAO and threads
    so I've got a pretty steep learning curve, but I'm making progress.

    I'm working right now on "compartmentalizing" the database object
    with the worker thread. I'll be posting again when I hit my next
    roadblock.

    Eric

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured