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