locked
Publish Project and include access database file RRS feed

  • Question

  • Hi all,

    i am new to visual studio 2017 and visual basic development.

    I am developing a simple app with an access database connected to.

    When i compile the app i find into the output folder the db and the executable file can correctly interact with it.

    The problem comes when i publish it and the setup.exe file is created, at the moment i run it apparently the software installs correctly but when it tries to run the app i get an error like the db was not fount at a pretty weird path i never defined.... here an example:

    C:\Users\XXXXXXX\AppData\Local\Apps\2.0\Data\4YQ264J8.OKT\0HE86EZ1.6W2\fran..tion_cf47d7591d0e9b8a_0001.0000_42fc36774fda86a5\Data\XXXXXX.accdb

    Any hint?

    Best regards

    Wednesday, August 15, 2018 5:45 PM

All replies

  • To get the path try

    System.Deployment.Application.ApplicationDeployment.CurrentDeployment.DataDirectory

    Or

    AppDomain.CurrentDomain.BaseDirectory

    e.g.

    Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Data","XXXXXX.accdb")

    If you have |DataDirectory| in your connection string in app.config the path would resolve itself if using TableAdapters 


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Wednesday, August 15, 2018 7:29 PM
  • This cryptic path is where clickonce deploys the app to. Each time you publish it will be different.

    Did you figure this out?

    If not, did you add the database file to your project and set the 'copy to output directory' property to 'copy always' or 'copy if newer'
    If you did then when the application is installed it will get copied to your 'weird path \data' directory. The path to it will be, like Karen said:

    Dim PathToDB As String
    
    PathToDB = "|DataDirectory|\MyDatabase.accdb"
    
    con.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source='" & PathToDB & "';Jet OLEDB:Database Password='" & pSwRD & "';Mode=Share Deny None"

    Friday, August 17, 2018 1:18 PM