473,396 Members | 2,024 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

possibly need a way of error trapping

I don't know if this should be here or in an Access forum but here goes

I have a VB6 program that uses an access database to record competitors and scores from a competion this works fine and i will call this database (A)

after each update is made database (A) copies itself to a preset location which I will call database (B)

so far everything is fine

at a remote location there is another computer with a cut down version of the main program which only allows competitors to view the results this uses a database I will call (C)

database (C) is a copy of database (B) and it also updates every time you return to the main selection screen

everything works fine for 99% of the time until database (C) attempts to copy (B) just at the point (A) is copying to (B) and the program on the remote computer crashes

and now to the question

does anyone know of a way of trapping the error caused by (C) trying to copy the database (B) when it is locked by (A) updating (B)
All I would require is for the remote computer to skip the update and just try again next time

I hope this makes sense and someone may be able to help me get past this annoyance as simply as possible

Many thank in advance

Regards Rob
Aug 15 '07 #1
20 1638
Killer42
8,435 Expert 8TB
On a slight tangent, you might be able to reduce the chances of it happening by doing the A->B copy in two stages.
  1. Copy A to B's location with a different name
  2. Delete B and rename the copy.
End result is the same, but you spend much less time with B unavailable.

Um...

I think I may have missed the point of the question. I was assuming you were talking about copying the database files to another location. Were you actually referring to copying records from one database to another?
Aug 16 '07 #2
pureenhanoi
175 100+
... after each update is made database (A) copies itself to a preset location which I will call database (B) ...
This is simple; create a lock file called (something.lock). No magic about the lock file. It's simply an empty file.
Before (A) updating (B), it creates a lock file. (C) will skip update from (B) till lock file is deleted.
When (A) completes updating (B), it delete lock file. So (C) can continue update data from (B).
Aug 16 '07 #3
This is simply create a lock file called (something.lock). No magic about the lock file. It simply an empty file.
Before (A) updating (B), it create an lock file. (C) will skip update from (B) till lock file is deleted.
When (A) completelly update (B), it delete lock file. So (C) can continue update data from (B).
Thats exactly the problem when it finds the lock file it crashes the program.
I need to find a way for it to skip the update when it finds the lockfile

Many thanks for the replies so far, keep them coming
Aug 16 '07 #4
On a slight tangent, you might be able to reduce the chances of it happening by doing the A->B copy in two stages.
  1. Copy A to B's location with a different name
  2. Delete B and rename the copy.
End result is the same, but you spend much less time with B unavailable.

Um...

I think I may have missed the point of the question. I was assuming you were talking about copying the database files to another location. Were you actually referring to copying records from one database to another?
No you were right the first time it is copying one database file but it doesn't matter which way i do it if it finds a lock file then it 'bombs' (and I must admit its only now and again) but I cant even make it restart automatically as it asks for a password to close it down so that the competitors cannot shut it down
Aug 16 '07 #5
Killer42
8,435 Expert 8TB
No you were right the first time it is copying one database file but it doesn't matter which way i do it if it finds a lock file then it 'bombs' (and I must admit its only now and again) but I cant even make it restart automatically as it asks for a password to close it down so that the competitors cannot shut it down
So, do you have any control over the program which is bombing? Can you rewrite it?

In any case, my suggestion should at least reduce the scale of the problem, since the file would be unavailable for a very brief period.
Aug 16 '07 #6
So, do you have any control over the program which is bombing? Can you rewrite it?

In any case, my suggestion should at least reduce the scale of the problem, since the file would be unavailable for a very brief period.
I wouldn't like to have to rewrite it but could certainly modify part of it, as i said at the start 99% of the time its fine but just occasionally it bombs.
The copy only takes a couple of seconds anyway (it is a finite database as it is only used once a year for one 4 day competition and is cleared back to zero at the end ready for next year)
Aug 16 '07 #7
Killer42
8,435 Expert 8TB
I wouldn't like to have to rewrite it but could certainly modify part of it, as i said at the start 99% of the time its fine but just occasionally it bombs. ...
Sounds, then, as though it should be relatively simple to have it retry if the copy fails. But I don't think we have anything like enough information about that program to advise.
Aug 16 '07 #8
pureenhanoi
175 100+
I wouldn't like to have to rewrite it but could certainly modify part of it, as i said at the start 99% of the time its fine but just occasionally it bombs.
The copy only takes a couple of seconds anyway (it is a finite database as it is only used once a year for one 4 day competition and is cleared back to zero at the end ready for next year)
The copy takes only a couple of seconds. The comptition apprear once a year. havent you got enought time to make the copy?
Aug 17 '07 #9
Killer42
8,435 Expert 8TB
The copy takes only a couple of seconds. The comptition apprear once a year. havent you got enought time to make the copy?
Must be a biiig file, huh. :)

Of course, I did once have a Windows file-copy dialogue tell me there were about 17 million seconds remaining...


Seriously, the file is only copied when updates are happening, so that would be during the competition.
Aug 17 '07 #10
pureenhanoi
175 100+
Must be a biiig file, huh. :)

Seriously, the file is only copied when updates are happening, so that would be during the competition.
Awh, thats bad. I havent understand his mind yet.
No problem. Thats technique is as the same as the lock file. (now, we're using another file - instead of lock-file- it can be called: mark-file)
+ (A) will send data to (B) every time it has new data. When sending complete, it create a mark-file (called: anything.mrk) to tell (C) that: it's time to update.
+ (C) will skip update data from (B) till it see the mark-file. When updating is completed, (C) removes mark-file (thats tell to (A) that: ready to receive newer data, and tell to it-selft that: the data from(B) is now old, no need to update)
+ (A) has new data, it must take a look that: havent (C) completed updating data yet?(by looks into mark-file). If mark-file still existing, (A) will skip sending data to (B) till mark-file is removed.
Aug 17 '07 #11
Awh, thats bad. I havent understand his mind yet.
No problem. Thats technique is as the same as the lock file. (now, we're using another file - instead of lock-file- it can be called: mark-file)
+ (A) will send data to (B) every time it has new data. When sending complete, it create a mark-file (called: anything.mrk) to tell (C) that: it's time to update.
+ (C) will skip update data from (B) till it see the mark-file. When updating is completed, (C) removes mark-file (thats tell to (A) that: ready to receive newer data, and tell to it-selft that: the data from(B) is now old, no need to update)
+ (A) has new data, it must take a look that: havent (C) completed updating data yet?(by looks into mark-file). If mark-file still existing, (A) will skip sending data to (B) till mark-file is removed.
I am now totally confused!!!

Surely if (C) can check for a 'mark-file' it could check for the presence of the 'lock-file' and just skip the copy if its there?
Aug 17 '07 #12
Killer42
8,435 Expert 8TB
I am now totally confused!!!

Surely if (C) can check for a 'mark-file' it could check for the presence of the 'lock-file' and just skip the copy if its there?
Yes, I'm inclined to agree.

Is it possible you could create a program which would simply copy the updated data from one database to the other, without having to copy the entire file? Or perhaps have A/B use the file in a shared mode, so C doesn't bomb when it tries to copy? (This last would have to be very thoroughly tested in case it allowed corruption of the data at C.)
Aug 17 '07 #13
pureenhanoi
175 100+
I am now totally confused!!!

Surely if (C) can check for a 'mark-file' it could check for the presence of the 'lock-file' and just skip the copy if its there?
Mark-file is abit diffrent from lock-file. If lock-file exist, (C) will skip update (because (A) havent finished sending data yet). If mark-file exist, (C) will update data from (B) because the mark-file used to caution: have new data.
If you use mark-file, forgot all about the lock-file.
The client machine (C) will check the mark-file each time it need infomation from database. If mark-file exist, call updating process before reading database infomation.
Say something about updating process:
+ First: Copy data file from (B) to (C) with different name.
+ Close current connection.
+ Re-Open connection with new Data Source (can change datasource by Connection String), that refers to new database.
+ Remove mark-file
+ No need restarting program.
+ You should store atleast 2 filenames. On client app start, use the first file name. On updating database, use the second. On updating again, use the first...and so on.
Aug 18 '07 #14
Killer42
8,435 Expert 8TB
Ah! So the "mark file" is basically a sign saying "fresh data here, get it while it's hot".
Aug 19 '07 #15
Mark-file is abit diffrent from lock-file. If lock-file exist, (C) will skip update (because (A) havent finished sending data yet)..
That would be fine if it would just skip the update cos it will try and update as soon as someone looks at another score which is very frequently
The problem is it won't skip if it can't update it just 'bombs'
all I need to know is how to make it skip on finding the lock file
Aug 19 '07 #16
Killer42
8,435 Expert 8TB
That would be fine if it would just skip the update cos it will try and update as soon as someone looks at another score which is very frequently
The problem is it won't skip if it can't update it just 'bombs'
all I need to know is how to make it skip on finding the lock file
For that, I think we will need more detail on what it is doing, and how, and what version of VB it is written in.

Can we see the code which is bombing? It might be as simple as doing something like On Error Resume Next and checking Err.Number to see whether the copy worked.
Aug 20 '07 #17
pureenhanoi
175 100+
That would be fine if it would just skip the update cos it will try and update as soon as someone looks at another score which is very frequently
The problem is it won't skip if it can't update it just 'bombs'
all I need to know is how to make it skip on finding the lock file
Now, say something about skip updating:
the old process maybe like:
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdShowScore_Click()
  2. score = getScoreFromDataBase()
  3. Display score
  4. End Sub
  5.  
the new process must be:
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdShowScore_Click()
  2. If isExistingMarkFile Then
  3.  call updatingDataBase()
  4. End If
  5. score = getScoreFromDataBase()
  6. Display score
  7. Ens Sub
  8. Private Function isExistingMarkFile() As Boolean
  9. Dim fileName As String
  10. fileName = "path to markfile"
  11. If Dir(fileName)<>"" Then
  12.  isExistingMarkFile = True
  13. Else
  14.  isExistingMarkFile = False
  15. End If
  16. End Function
  17. Private Sub updatingDataBase()
  18. 'use each diffent file name for each time need updating
  19. If currDbname = "(C)\db2.mdb" Then
  20.  currDbName  = "(C)\db1.mdb"      'here is global varriable, use to store current database file name
  21. Else
  22.  currDbName = "(C)\db2.mdb"
  23. End If
  24. FileCopy "(B)\db1.mdb" currDbName    'overwrite old file if you need
  25. 'close current connection
  26. con1.Close
  27. 'refer connection to new database
  28. con1.ConnectionString ="Provider=Microsoft.Jet.OLEDB.4.0; Data Source='" & currDbname & "'"
  29. 're-open the connection
  30. con1.Open
  31. 'remove the mark-file
  32. Call Kill "path to mark-file"
  33. End Sub
  34.  
Aug 20 '07 #18
Killer42
8,435 Expert 8TB
...the new process must be:
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdShowScore_Click()
  2. If isExistingMarkFile Then
  3.  call updatingDataBase()
  4. End If
  5. score = getScoreFromDataBase()
  6. ...
I disagree, not in principle, but with the way it's implemented. This sort of thing should be handled in the getScoreFromDataBase routine, not the user interface. In other words, you shouldn't have to check for the "mark file" in each button-click routine.
Aug 20 '07 #19
pureenhanoi
175 100+
I disagree, not in principle, but with the way it's implemented. This sort of thing should be handled in the getScoreFromDataBase routine, not the user interface. In other words, you shouldn't have to check for the "mark file" in each button-click routine.
Let see, why did you need checking for mark-fle in getScoreFromDatabase()? Each time user hit the button, we call getScoreFromDataBase() one time. That mean, if i placed the check function outside or inside the getScoreFromDatabase(), the check function will be called each time for the hit button event.
If you have another way to reduce the frequently of check-function, maybe its better to place check-function inside getScoreFromDatabase().
But thats not the problem.You can place the check-function anywhere you like, but you should check for newer data each time user need display data, or the data will be old.
Aug 20 '07 #20
Killer42
8,435 Expert 8TB
... But thats not the problem.You can place the check-function anywhere you like, but you should check for newer data each time user need display data, or the data will be old.
That's precisely my point. It should be "encapsulated" within the database lookup function, as a standard part of the process. Not something that the caller has to remember to check before calling the lookup.
Aug 20 '07 #21

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Erencans | last post by:
Hi to all, I want to error handling in ASP. But i think that ASP is not enough for error handling. I have got two chance. 1. I can prapare an error page and control throught IIS. 2. I can use on...
3
by: Paul | last post by:
I have an Access 2000 database with a form that is giving me some major headaches. When you open the form, it displays all records and allows editing, but has AllowAdditions set to False so that...
13
by: deko | last post by:
I use this convention frequently: Exit_Here: Exit Sub HandleErr: Select Case Err.Number Case 3163 Resume Next Case 3376 Resume Next
3
by: Nathan Bloomfield | last post by:
Hi there, I am having difficulty with a piece of code which would work wonders for my application if only the error trapping worked properly. Basically, it works as follows: - adds records...
3
by: windandwaves | last post by:
Hi Gurus Does anyone know how I set the error trapping to option 2 in visual basic. I know that you can go to tools, options and then choose on unhandled errors only, but is there a VB command...
2
by: Bill Stock | last post by:
I have a subform which is causing a 3314 (Field can't contain a null value because required is set to True) error. I solved this problem by trapping it in the before update event. But then I...
2
by: Captain Nemo | last post by:
I'm still using Office 2000 myself, but some of my clients have Office 2003. I've recently added a piece of code to create an instance of Word, open a document, fill in the blanks and become...
9
by: 47computers | last post by:
Pretty new to PHP, I recently started learning about error trapping. As of right now, I include the following into a page in my website: -------BEGIN PASTE-------- error_reporting(E_ERROR |...
1
by: Elmo Watson | last post by:
Up until now, I've done all the work (gui/front end programming, classes, etc) I've done all my error trapping (try/catch) in the methods in the code behind. Now I've got an opportunity to do...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.