02-01-2013 05:40 AM
Hello!
We have a very well working measurement software written in LabView. However we would like to backup the data files regularly. We want to be able to do this even during measurement and while the software is writing to the files. Now when we try to do so, we occasionally face "Error 5 occurred at Open/Create/Replace File" (in "Write To Spreadsheet File") because another software (backup, windows stuff, else...) accesses the files also. Now from my point of view this kind of concurring file access should not be a problem since LV is the only software writing to the files. There are 3 possible solutions I can think of:
the last one should be the proper solution and also work on different OS since the copy/moving stuff should be atomic operations and thus safe in this context. However I implemented the solution and still have exactly the same problem but now in "Move File"... I am starting to doubt if it is possible to solve this issue at all and thus desparatly need help here! As I can see there is not lock or mutex on the file and no need for LV to raise an error (I think it is done as warning for future possible conflicts)... I assume it is some hidden/strange badly documented Windows API "feature" LV is using to detect those other accesses and it results in a behaviour I cannot change or fix - so what to do here...?
Thanks a lot in advance for any helpful suggestions or hints! Greetings
Ursin Solèr
Solved! Go to Solution.
02-01-2013 10:40 AM
My sense the problem is that the backup software tries to get an exclusive lock on all the files that it is going to backup. They do this on the assumption that you don't want to save a file to which someone else is actively writing - which, by the way, usually isn't a bad assumption.
Are you needing to make this change without any modifications to the original LV program?
Mike...
02-04-2013 02:48 AM
> the backup software tries to get an exclusive lock on all the files that it is going to backup
I am not sure with this, since essentially EVERY other software (except notepad which just open, reads to memory and closes again) causes issues and I doubt e.g. MS Word to apply exclusive locks on opened files...?! But I don't know...
> Are you needing to make this change without any modifications to the original LV program?
Would be nice but no! I was trying to solve it from the labview program (since this is the one complaining and having issues) as mentioned, but not even the "pedestrian way" (copy to temp. and do it there in order to copy it back afterwards) which should work on EVRY OS (linux, mac, windows) does the trick...?! So what to do?
Greetings
Ursin
02-04-2013 06:03 AM
May be I should also add; it works as expected with TDMS file format - but I would prefer to write a Spreadsheet-Text-File.
02-06-2013 09:48 AM - edited 02-06-2013 09:51 AM
I have to correct myself here:
Hope this helps someone else too.
Using this method I can now use e.g. MS robocopy in order to backup or mirror all data files while the LV program writes into them. A very basic and important thing for a logger... 😉
Greetings
02-06-2013 10:13 AM
It's all about the method you want to write. Assuming you want to always backup what you write, I'd create a wrapper for your write functions to take two inputs, and write two files all the time. In your example, I'd replace the write Spreadsheet Vi with something like this:
Which will request two paths and both files will be written the same way. You control it when you want to save data. Not some external program.
"I won't be wronged. I won't be insulted. I won't be laid a-hand on. I don't do these things to other people, and I require the same from them." John Bernard Books
02-07-2013 02:17 AM
I Think you must have missunderstood me; the problem is you cannot open and write to a file while another external program has it opened too with exclusive access. Consider following code:
If you open the file during the "Wait" (it is closed then because "Write to Spreadsheet" does open, write, close) e.g. with MS Word wich does an exclusive open (allowing exclusive access only) then during the next loop your program will crash with error 5.
The solution I mentioned is to open it first in LV an keep it open all the time:
which prevent e.g. MS Word to open it exclusively but read-only!
What you mentioned is regarding a backup - I considered this double write long before, but it is no good solution, beacuse e.g. the other drive might be a network drive and I don not want to handle absent drives - that's something the external backup tool should do.