Eny, I am using code to create a backup copy of the sqlite3 database file on my hard drive. This is the same database file that my program is currently using to access data. I believe it is probably opened for exclusive use, not allowing even read share. When this code executes an error code is returned telling me that the database file that was accessed, could not be opened for read. My question to the group, was aimed at finding an answer as to why my running program cannot access this file for copy (read access) and yet other programs like a dos window command, or windows explorer, can access and copy the file without problems (while my program is still running.) I don't have specific examples of the 'copy code' that I tried and which didn't work. I used about 15 different filecopy versions found in three days worth of searching on the net. Suffice it to say, that I tried every copyfile, filecopy, and other variant of copy function within delphi and lazarus including some posted 'custom' stream versions etc, and none of them could open the database file for read access to copy it. I tried every available file open mode for sharing, denying access etc without success. Some of the copy variants required PChar conversion vice string, and it made no difference. anybody out there can test this if you have an sqlite3 program running, just try to copy the database file while it's running. I finally ended up calling a dos command to copy the damn file:
uses ..., dos, ....
...
// doscmd1 does backup of db file to standard directory (./backup/xxx.db)
doscmd1 := '/c copy /B ' + filesource + ' ' + filedest;
Exec (GetEnv('COMSPEC'), doscmd1);
...
This is clunky at best as it flashes open the command window for a second or two while doing the copy. No other lazarus or delphi, or custom, copy command has been able to open the file for read access. I have to fix this since I want the program to be cross-platform, and using dos to copy a file won't work on linux or mac.
The code I'm using right now is huge. If I can get time, I will try to put together a small sample program that I can put on the forum, so you guys can have a whack at trying to copy the .db file from within the code. Meanwhile, I really do appreciate all the replies.
Mike