PDA

View Full Version : lock sqlite3 db for one user at a time



gvanassche
01-06-2010, 06:21 AM
Dear all,

I want several people on the network to use the same database, but only one at the time. So it the application is being used by one person, the other ones should be locked out.

Does anyone have an idea what would be the easiest way to do this?

thanks

gert

mystica
01-06-2010, 11:56 AM
Stick this in your On Page Show event:


local tbProcesses = System.EnumerateProcesses();
local bAlreadyRunning = false;
for process_id, file_path in tbProcesses do
tbFile = String.SplitPath(file_path);
if(tbFile.Filename .. tbFile.Extension) == _SourceFilename then
if bAlreadyRunning then
Dialog.Message("Already Running", _SourceFilename .. " is already running.");
Application.Exit();
end
bAlreadyRunning = true;
end
end


It will check to see if an instance of your program is already running and if so,
prevent subsequent instances from running, advising that the program is already in use.

longedge
01-06-2010, 01:38 PM
I only use MS Access and SQL Server 2005 so I'm not sure about SQLite but it is, so I just read, fully transactional so multiple users aren't necessarily a problem. I'm sure other forum members will pick up on this aspect if this is incorrect :)

Obviously you are talking about users on different machines all connected to the same network so how about getting you project to checking for 'marker' text file when it runs, if it exists close after a dialogue message and if it doesn't exist, then create one and continue. Delete the file on application close.

p.s. - the important thing is to use fully qualified UNC's and not drive mappings!!

gvanassche
01-06-2010, 01:59 PM
longedge, mystica,

yes I need the tool to be executed from different machines, using the same database. The db is basically generating a unique number that needs to be used in other applications. If the same db can be used by different people at the same time, I risk that the generated numbers are not unique.

thanks for your tips,

gert