新建线程无法进行数据库操作,连Open ()都不能.
我是利用DAO进行数据库操作的.
class CMyDao : public CDaoRecordset
CMyDao mydao;我跟踪了一下,一运行到mydao.Open()就出现Unhandled exception in full.exe(DAO350.DLL):0cC0000005:Access Violation.
麻烦各位帮忙看一下是哪里出了问题.

解决方案 »

  1.   

    你有用临界资源把你的
    mydao对象 框住吗?
    我的意思是
    EnterCriticalSection()
    使用mydao
    LeaveCriticalSection()
      

  2.   

    这和线程安全有什么关系,肯定是你在新线程里面没有处理好。
    CoInitialize()有没有在新线程里面初试化??
      

  3.   

    TO:robin_yao(认真)
    这和临界资源无关吧.
    线程在进行数据操作时,其他地方就没有再对数据库进行操作了.
    而且我用Mutex试过了,还是出现同样的问题
      

  4.   

    App::InitInstance() 
    {
    // TODO: Add your specialized code here and/or call the base class
    HRESULT   hr   =   OleInitialize(NULL);
    if   (hr   ==   S_FALSE)
    {
    OleUninitialize();
    }
    //   Call   if   using   OLE   Controls
    AfxEnableControlContainer();
    //   Register   all   OLE   server   (factories)   as   running.   This   enables   the
    //   OLE   libraries   to   create   objects   from   other   applications.
    // COleObjectFactory::RegisterAll();
    //   TODO:   Add   your   specialized   code   here
    return   CWinApp::InitInstance();
    }在dll的InitInstance启动OLE试试