Results 1 to 8 of 8

Thread: [RESOLVED] Very strange behaviour of App.Path

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2013
    Posts
    783

    Resolved [RESOLVED] Very strange behaviour of App.Path

    Hello VBForums experts
    A strange behaviour of App.Path is driving me mad.

    This is my small application after compilation and installation

    Name:  111.png
Views: 225
Size:  5.6 KB

    This is my connection string.
    In a module:
    Code:
    Public MyDBPath As String
    in Sub Main
    Code:
     MyDBPath = App.Path & "\Vdata.mdb"
    In the form
    Code:
    Public Sub connect()
    Set DB = New ADODB.Connection
    Set RS = New ADODB.Recordset
    DB.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & MyDBPath & ";Persist Security Info=False;Jet OLEDB:Database Password=123456"
    RS.CursorLocation = adUseClient
    End Sub
    I also tried with the following:
    Code:
    Public Sub connect()
    Set DB = New ADODB.Connection
    Set RS = New ADODB.Recordset
    DB.Open "Provider=Microsoft.Jet.OLEDB.4.0;Jet OLEDB:Database password=123456; Data Source=" & App.Path & "\Vdata.mdb"
    RS.CursorLocation = adUseClient
    End Sub
    According to this string, the database is supposed to be in the same folder as the exe file.
    Unfortunately the program seem not taking this into account.
    Because even if I delete the Vdata.mdb from the App.Path, the program is working fine.

    Name:  22222.png
Views: 198
Size:  4.7 KB

    I wonder which Vdata.mdb my program is using since the one in the App.Path is deleted.

    I checked the existence of the files.

    Code:
    MsgBox App.Path & IIf(Right$(App.Path, 1) <> "\", "\", "") & App.EXEName & ".exe"
    I get the full path of the program.

    Code:
    If Dir(App.Path & "\Vdata.mdb") <> vbNullString Then MsgBox "yes"
    the msgbox returns yes.

  2. #2
    Addicted Member Wolfgang Enzinger's Avatar
    Join Date
    Apr 2014
    Location
    Munich, Germany
    Posts
    160

    Re: Very strange behaviour of App.Path

    My crystal ball says that your program is installed somewhere below the Programs folder, does not have Admin privileges, is not manifested "as invoker" and so Vdata.mdb has been virtualized. Right? If you search for Vdata.mdb you'll find it somehwere below AppData\Roaming IIRC.

    Move your Vdata.mdb to a folder where the program actually got write permissions (real ones, not virtual).

    Wolfgang

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2013
    Posts
    783

    Re: Very strange behaviour of App.Path

    Thank you sir

    I installed the application in the partition D and it is recognizing the App.Path.

    This means I can't install the application under the Programs folder?

  4. #4
    Addicted Member Wolfgang Enzinger's Avatar
    Join Date
    Apr 2014
    Location
    Munich, Germany
    Posts
    160

    Re: Very strange behaviour of App.Path

    Quote Originally Posted by samer22 View Post
    This means I can't install the application under the Programs folder?
    Not as long as your program tries to write to a folder it doesn't have write permission for; this applies, among others, to the Programs folder and its subfolders.

    Files like Access databases or INI files which the program attempts to write to should be placed in a separate, non-protected folder.

    Clarification: App.Path works correctly under all circumstances; the problem is that with virtualisation in effect Windows does not use this path but silently works with a copy of the file located somewhere else.

    HTH Wolfgang
    Last edited by Wolfgang Enzinger; Feb 17th, 2018 at 08:10 AM. Reason: typo corrected, some clarification

  5. #5
    Frenzied Member
    Join Date
    Feb 2015
    Posts
    1,025

    Re: Very strange behaviour of App.Path

    Quote Originally Posted by samer22 View Post

    This means I can't install the application under the Programs folder?
    You can install the application under the Programs folder.
    But Vdata.mdb must be located somewhere else, and your application modified to point to that 'somewhere else'.

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2013
    Posts
    783

    Re: Very strange behaviour of App.Path

    Thank you very much
    I understand now
    Just a question out of curiosity:
    Is there a way to find the Vdata.mdb file with which the program is working?
    I looked in the roaming folder but there is no file with the name of Vdata.mdb
    thank you

  7. #7
    gibra
    Guest

    Re: Very strange behaviour of App.Path

    Quote Originally Posted by samer22 View Post
    Is there a way to find the Vdata.mdb file with which the program is working?
    I looked in the roaming folder but there is no file with the name of Vdata.mdb
    thank you
    The folder is named VirtualStore and you can find it in

    C:\Users\[username]\AppData\Local\VirtualStore\

  8. #8

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2013
    Posts
    783

    Re: Very strange behaviour of App.Path

    gibra
    You are great
    yes It is there

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