Solved

Application not shuting down normally.

Posted on 2002-04-16
12
163 Views
Last Modified: 2010-05-02
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
0
Comment
Question by:bmatumbura
  • 4
  • 3
  • 3
  • +2
12 Comments
 
LVL 5

Expert Comment

by:rkot2000
ID: 6945349
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
 
LVL 5

Expert Comment

by:rkot2000
ID: 6945355
if you are subclassing your form(s) you need to relase all hooks.
0
 
LVL 5

Expert Comment

by:kcm76
ID: 6945765
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
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6945845
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
 
LVL 5

Expert Comment

by:rkot2000
ID: 6945856
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
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6946022
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 2

Expert Comment

by:corvanderlinden
ID: 6947016
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
 
LVL 11

Author Comment

by:bmatumbura
ID: 6949878
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
 
LVL 2

Accepted Solution

by:
corvanderlinden earned 100 total points
ID: 6950078
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
 
LVL 5

Expert Comment

by:rkot2000
ID: 6950422
re numega: not everybody can pay up to $3000 per numega.
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6950505
I am with rkot regarding Numega but in this case, the trial period could be enought.
0
 
LVL 2

Expert Comment

by:corvanderlinden
ID: 6950519
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

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now