Application not shuting down normally.

I created an application that connects to an Access database using ADO. The problem I have is: If I use the application's File->Exit menu, the apllication always stays in memory. I have to press ALT-CTRL-DEL to end it's task. If I use the control menu (or the X at the top right corner of the form) I get an application error in Windows and the application terminates abnormally. What could be the problem?

The Database connection is declared in the Declarations area as:

  Dim dbConn as New ADODB.Connection

The code in the exit menu is:

Unload Me

My Form_QueryUnlod(Cancel as Integer) event is as follows:

Private Sub Form_QueryUnload(Cancel As Integer)
  If MsgBox("Are you sure you want to exit this application?=vbno Then
  Cancel = True
End Sub

The Form_Unload event contains this code:

Private Sub Form_Unload()
  Dim f As Form
  For Each f in Forms
    If f.Name <> Me.Name then Unload f
  Next
  dbConn.Close
  set dbConn = Nothing
End Sub
LVL 11
bmatumburaAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
corvanderlindenConnect With a Mentor Commented:
Use Numega's tools

http://www.compuware.com/products/numega/index.htm

you could use tracing the execution path of your code to a log file, but I doubt that solves the problem. This is typically a problem where the offending code can be anything (even something that happened at startup time)

What happens if you compile your exe with debugging info. Does the problem then still exists?


0
 
rkot2000Commented:
you may have some global variables in the memory;
try to use this :

Private Sub Form_Unload()
 Dim f As Form
 For Each f in Forms
   If f.Name <> Me.Name then
     Unload f
     set f = nothing
 Next
 dbConn.Close
 set dbConn = Nothing
 set ThisFormObject = nothing
End Sub

or you can add

end before end sub

like this
end
end sub

0
 
rkot2000Commented:
if you are subclassing your form(s) you need to relase all hooks.
0
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

 
Chandramouli kArchitectCommented:
If u r using MDI envn., try using **End**. as rkot suggested. This will close all the forms (including Hidden forms) associated with the project workspace.

Otherwise, the problem is to be found out......

0
 
Richie_SimonettiIT OperationsCommented:
Do Not use End statement!
Private Sub Form_Unload()
dbConn.Close
set dbConn = Nothing

Dim f As Form
For Each f in Forms
   If f.Name <> Me.Name then Unload f
Next
End Sub
0
 
rkot2000Commented:
what is wrong with end statement?
True, you need to release remote objects, release connections and end.

it's VERY, VERY bad to use with ActiveX servers(ocx,dll or exe) but it's ok to use with  client exe pc.



It works like garbage collector in Studio Net
0
 
Richie_SimonettiIT OperationsCommented:
using End statement is like trying to stop a racer car... against a wall.
"....
....
It works like garbage collector in Studio Net"
Sure it does, so object relesing is done when VB wants to do or when it was time to do or next monday.
Garbage collector from .net not releases object inmediately.
0
 
corvanderlindenCommented:
This is a nasty problem. I suggest using Numega's smartcheck or something like that. The offending code can be anywhere in your program.

About the End statement

The only case when Visual Basic does not invoke the Class_Terminate event is when you abruptly stop a program using the End command from the Run menu or the End button on the toolbar. This immediately stops all activity in your code, which means that no Class_Terminate event will ever be invoked. If you inserted critical code in the Terminate events—for example, code that releases Windows resources allocated via APIs—you'll experience problems. Sometimes these are big problems, including system crashes. By the same token, NEVER TERMINATE a program using an END STATEMENT in code: This has exactly the same effect, but it's going to create problems even after you compile the application and run it outside the environment.
0
 
bmatumburaAuthor Commented:
My project does use a lot of API's. Each form I used has code that sets each object I used to Nothing in the unload event. What amazes me is the Application doesn't crash when run in the IDE. VB does not report any errors either. These errors only occur when I run the create .EXE. How can I trace the execution of code in the application to check at what point the error occurs?
0
 
rkot2000Commented:
re numega: not everybody can pay up to $3000 per numega.
0
 
Richie_SimonettiIT OperationsCommented:
I am with rkot regarding Numega but in this case, the trial period could be enought.
0
 
corvanderlindenCommented:
I suggested Numega, because I had a similar problem in our ADO application using Oracle. Also, only failure on application exit on compiled app

All the desk checking and debugging we did, did not take us closer to the solution. Numega's Smartchecker made us aware of a problem in the Oracle db drivers

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.