Catching "run-time errors" - can it be done?

VBKid04
04-15-2004, 06:42 PM
I have had my system running on and off in memory for some time now (maybe a couple of hours)...

On my most recent compilation/execution of the system, I was able to open and close several forms before I was presented with an error.

After I had opened and closed around 5 forms, and tried to open another, this error appeared:

Error -2147467259
Unspecified Error

Highlighting in yellow this line in my Form_load:

db.Open "PROVIDER=Microsoft.Jet.OLEDB.4.0;" & "Data Source=" & ConnPath & "\MyDatabase.mdb";



I have also just tried adding a record, it works fine.
I add 5 records, adding them fine.
When I get to around 10, this error comes up again, and points to the same line on my connection string.


NOTE: Nowhere have I closed my database (eg. db.close)

Everytime I am saving my records I am refreshing the form to be sure it is up to date.

Could this be causing the problem?

Do I need to close the database and then reopen after every transaction ?


Thanks

VBKid04
04-15-2004, 07:31 PM
Something else I had forgotten about, it did this on me once, but is now doing it again...

When I try to compile, as soon as it starts to run it throws the error:

Error -2147467259
Unspecified Error

highlighting the same line on me in my Login form_load


Any ideas?

LaVolpe
04-15-2004, 07:41 PM
does this apply? The error code you provided seems to be a generic code.
http://www.visualbasicforum.com/printthread.php?t=116475

VBKid04
04-15-2004, 09:43 PM
I know, it seems to be generic - I've noticed it come up before but with different error messages...

Error -2147467259 usually seems to relate to missing recordsets / records / values (ie. maybe a null value has been specified)...


But this particular error:
Error -2147467259
Unspecified Error

Is of absolutely no help at all!

Something makes me wonder, because sometimes my system runs okay for a long time, and then all of a sudden it starts playing up, is it because of the size/amount of recordsets/connections that are being opened and is the computer running out of memory ?

How much memory does it typically use (and is it RAM or HD space it uses) to open a recordset of about 100 records?

wengwashere
04-15-2004, 10:38 PM
How much memory does it typically use (and is it RAM or HD space it uses) to open a recordset of about 100 records?

a hundred records is quite small and it doesnt need that much hardware resource.

MKoslof
04-16-2004, 06:15 AM
No, you don't have to open and close a connection after every transaction. You should check your code an make sure you don't have any obvious errors (such as accidently cutting off your connection, etc.)

LaVolpe
04-16-2004, 07:26 AM
For you db wizards out there? doesn't ADODB and/or DAO have an option to declare connections with the "WithEvents"? If so, a more meaningfull error my be returned in the onerror event.

MKoslof
04-16-2004, 07:30 AM
Yes, you can use WithEvents. If so, there are some other events you can code and delegate. This provides you with a more flexible means of controlling the events within your ADO objects. It really won't return a more meaningful error unless you trap it in the right place.

VBKid04
04-16-2004, 08:11 AM
I don't have any obvious errors, my code has been checked and checked and checked.

On some forms I am using the WithEvents method of declaring recordsets.


I personally am of the opinion that this error is something to do with memory.

Sometimes I will run my system, and it will run fine for around 25 opening and closings of forms.

The next time I run it, it will only allow me to open and close 5 forms before it throws that error.

After another few attempts I cant even get my system to start, the login screen doesnt even appear before that error is thrown...

:(

VBKid04
04-16-2004, 06:17 PM
Have setup an error handler here but just want to check it will definitely work, as I need to create it in quite a number of places.

Wouldnt want an error handler throwing an error!


Select Case (Err)
Case -2147467259

If Err.Description = "Unspecified Error" Then
MsgBox ("An Unknown error has occured").

Else: MsgBox ("You have specified null values for some fields and this is not
allowed")

End If

Exit Sub
End Select


Just wondering if that line If Err.Description = "Unspecified Error" Then

is correct and can be used really ?


Thanks

MKoslof
04-16-2004, 06:36 PM
Well, open the task manager while running your application...how much memory is being consumed. How many forms are you opening at once? Are you SURE you are closing all connections when finished with them. A standard VB app should have no memory issues.

VBKid04
04-16-2004, 06:40 PM
How much memory is consumed - not even 2%

How many forms open at once - only 1.

Close the others when i exit them

How many DB connections ? Probably quite a few...

How many recordsets? Could be anything up to about 15

I assume that Form Unload (when the form is closing) unloads all the DB connections also ?

MKoslof
04-16-2004, 06:42 PM
NO...this is bad practice.

You need to close all recordsets and connections yourself. cn.close, rs.close, etc. Then, unload your form.

VBKid04
04-17-2004, 08:53 AM
Okay to get around this I am having to setup the same error handler on all buttons and forms in my project.

I cannot get around this as I had asked earlier about setting up a global error handler and was told it wasnt really possible...

Besides that I cant see any other way around it :/

VBKid04
04-17-2004, 08:57 AM
No-one is sure if this will work or not?

Please let me know if it will as I have to use it in quite a lot of places throughout.

Thanks.

VBKid04
04-17-2004, 09:10 AM
I know you can catch when VB throws an exception like "the database is locked" etc. but if you program should come across a run-time error, is it possible to catch it ?

How should this code (for catching exceptions) be changed to catch a run-time error?


On Error GoTo ErrorHandler

ErrorHandler:

Select Case (Err)
Case -291594600
MsgBox ("User cancelled the process")

Exit Sub

End Select


And is there anyway I should change my code to more successfully catch more errors?


Thanks

reboot
04-17-2004, 09:11 AM
Ever consider trying it?

webbone
04-17-2004, 01:36 PM
There are a multitude of errors which might occur - well tested code can help with preventing these from occuring, but problems do arise (especially when dealing with multiple OS's, etc.).

You can add as many different errors to your Select statement as you feel necessary - and then have a "Case Else" to catch anything you havent' specifically handled. The big question is what to do when an error occurs, i.e. is it recoverable or not? Frequently all you can do is to put up a message box with a little bit better explanation of when and where an error occured which can help you find and fix potential problem spots in your code.

Flyguy has posted a good tutorial on error handling that you might want to check out: http://www.visualbasicforum.com/showthread.php?t=16987

VBKid04
04-17-2004, 03:22 PM
Ive been checking books and the web but cant get any good info on how Err.Description works....

I have a generic error (error code -2147467259) which brings up an error for many different reasons...

Sometimes its if a value is null, other times its because a value is filled incorrently, other times it may be because a record cannot be updated....

Therefore I think i need to use Err.Description - but how does it work?

Does it basically operate like this or have I got this wrong?


FormError:

Select Case Err.Number
Case -2147467259

If Err.Description = "You have entered null values" Then
MsgBox "Do Something"
If Err.Description = "You cannot update at this time" Then
MsgBox "Do Something Else"
If Err.Description = "You have filled a record incorrectly" Then
MsgBox "Do Something Different Again"
End If

End Select
Exit Sub



If it doesnt operate like this, can someone please provide a sample of how it works? Thanks

VBKid04
04-17-2004, 03:28 PM
yes I have tried it, I am throwing errors on purpose to go to the Err.Description line, but I can't get it to go the line where it says:

If Err.Description = "Unspecified Error" Then
MsgBox ("An Unknown error has occured").

it always seems to go to the Else bit.


So I am assuming it is possibly wrong ? But how do I fix it ?

reboot
04-17-2004, 03:56 PM
Try

If InStr(Err.Description, "Unspecified Error") Then

wengwashere
04-18-2004, 06:54 PM
How much memory is consumed - not even 2%

How many forms open at once - only 1.

Close the others when i exit them

How many DB connections ? Probably quite a few...

How many recordsets? Could be anything up to about 15

I assume that Form Unload (when the form is closing) unloads all the DB connections also ?

How do you close your DB Connections? In which event or when do you call it?

VBKid04
04-19-2004, 09:47 AM
db.Close

close them when I exit the form - thats about it I think.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum