CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    May 2001
    Posts
    1

    Previous Instance

    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.


  2. #2
    Join Date
    Feb 2001
    Location
    Stamford CT USA
    Posts
    2,167

    Re: Previous Instance

    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

    Good Luck,
    -Cool Bizs

  3. #3
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    Re: Previous Instance

    ...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.
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

  4. #4
    Join Date
    Apr 2000
    Location
    South Carolina,USA
    Posts
    2,210

    Re: Previous Instance

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured