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. Run Time Error When Using CDatabase

Run Time Error When Using CDatabase

Scheduled Pinned Locked Moved C / C++ / MFC
c++databasehelpsysadminquestion
3 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
    Muhammad Asim Ghaznavi
    wrote on last edited by
    #1

    Hi All, I am developing a service for win 2000 on VC++, that service accesses the databse to retreive some information like user id etc. I am using CDatabase and CRecordset classes for accessing the database. but the problem is that when i call a method (that access the database) from the main service loop, it reports a Run time Error, and after that Service Application terminates. the line is CDatabase db; db.OpenEx("DSN=MailMove;SERVER=LOCALHOST;UID=;PWD=;DATABASE=;"); This is working fine in regular MFC Application (eg dialog based) but when i call the same method through the service's main loop, it reports the error.:confused: Please point out any one knows about what is going wrong. Its an urgent. Thanks in advance. bye Asim

    R 1 Reply Last reply
    0
    • M Muhammad Asim Ghaznavi

      Hi All, I am developing a service for win 2000 on VC++, that service accesses the databse to retreive some information like user id etc. I am using CDatabase and CRecordset classes for accessing the database. but the problem is that when i call a method (that access the database) from the main service loop, it reports a Run time Error, and after that Service Application terminates. the line is CDatabase db; db.OpenEx("DSN=MailMove;SERVER=LOCALHOST;UID=;PWD=;DATABASE=;"); This is working fine in regular MFC Application (eg dialog based) but when i call the same method through the service's main loop, it reports the error.:confused: Please point out any one knows about what is going wrong. Its an urgent. Thanks in advance. bye Asim

      R Offline
      R Offline
      Ramu Pulipati
      wrote on last edited by
      #2

      A guess: Run() on Win32 Service is generally executed on different thread. And CDatabase (may/may not) need MFC initialisation before its being invoked. And AfxWinInit is used to initialse MFC for non-MFC applications. Add the following line in the very begining of the Run() Method if (!AfxWinInit(::GetModuleHandle(NULL), NULL, NULL, 0)) { cerr << "MFC failed to initialize!" << endl; return 1; } and maybe an instance of CWinApp. Check AfxWinInit API in MSDN for more details. Hope this helps! Ram

      M 1 Reply Last reply
      0
      • R Ramu Pulipati

        A guess: Run() on Win32 Service is generally executed on different thread. And CDatabase (may/may not) need MFC initialisation before its being invoked. And AfxWinInit is used to initialse MFC for non-MFC applications. Add the following line in the very begining of the Run() Method if (!AfxWinInit(::GetModuleHandle(NULL), NULL, NULL, 0)) { cerr << "MFC failed to initialize!" << endl; return 1; } and maybe an instance of CWinApp. Check AfxWinInit API in MSDN for more details. Hope this helps! Ram

        M Offline
        M Offline
        Muhammad Asim Ghaznavi
        wrote on last edited by
        #3

        Hi, Thanks for replying, I have inserted the code that u have asked, but this code is causing a "Debug Assertion Failed!" error. :( Please tell me how to tackle the problem. I have an Application that can run in two modes, i.e. GUI MFC Application and NT Service. Please reply as soon as Possible. Thanks alot Asim

        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