Click to See Complete Forum and Search --> : Previous Instance
sucricus
May 11th, 2001, 04:32 AM
Trying to create multiple instances of a standard exe program that will be accessing the same database.
How should the database be managed?
Because when one instance of the program deletes a record in the database and another instance tries to edit the same record, it will cause problem.
Was thinking of using "app.PrevInstance" property to detect if another instance has been created and lock the database to be a read-only grid.
But how would it be possible to detect that the first instance has released the database?
Is there any other help available?
Thank you.
coolbiz
May 11th, 2001, 06:41 AM
If you're using ADO and working against most of the common Relational DBs (Oracle, MSACCESS, SQL), then you should be okay since those DBs support Row Level Locking. It means, if someone is doing something (other than reading) to a record, it should be locked and if any other processes try to do the same to the same record, it will cause an error.
You can then trap this error in VB and prompt to the user that record is being locked by someone else.
-Cool Bizs
Cimperiali
May 11th, 2001, 08:55 AM
...moreover (=read first other answer), app.PrevInstance will tell you there is another instance activated only on your machine, and only if it has been activated in same folder (if you make a copy of an exe in another folder and launch it, it will not detect a prevInstance running from other dir)...
Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood Bruno Paris and all the other wonderful people who made and make Codeguru a great place. Come back soon, you Gurus.
John G Duffy
May 11th, 2001, 12:08 PM
App.PrevInstance is only marginal i detecting if another copy of your program is running. THe following Sample uses the "FindWindow" API to locate another instance of a APP using its Title.
It overcomes the problem of not detecting a match if running from different folders
' Form level Code
option Explicit
private Sub Form_Load()
Dim iRet as Long
' Check if THIS APP is currently running.
' Zero result says no, Non-Zero says Yes
iRet = IsItRunning(App.Title) '
MsgBox iRet
' is another app running?
' Passing another Application Title, Check if it is currently running.
iRet = IsItRunning("Program Manager")
MsgBox iRet
End
End Sub
'
'
' Module level code
option Explicit
private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
(byval lpClassName as string, byval lpWindowName as string) _
as Long
'*******************************************************************************
' IsItRunning (FUNCTION)
'
' PARAMETERS:
' (In/Out) - who - string -
'
' RETURN VALUE:
' Long - 0 if application is not running
' - hwnd of the application window
' DESCRIPTION:
'
'*******************************************************************************
Function IsItRunning(who as string) as Long
Dim OldTitle as string
' Save existing Title in case testing for myself
OldTitle = App.Title
App.Title = "Some Junk Title"
'Attempt to get window handle
IsItRunning = FindWindow(vbNullString, who)
' Restore Applications title
App.Title = OldTitle
End Function
John G
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.