0

I am working in Visual Basic 2022 making a database for a doctor's office, but when I package and create a Setup the address of my computer is saved in the path of the access database and when I run my application it says the following " C:\User\project\patients.accdb is not a valid path, how can I correct this, thanks for your help

modificated this property

or I don't know if I'm doing the Setup wrong

SanLey
  • 1
  • 1
  • The following may be of interest: [Environment.SpecialFolder Enum](https://learn.microsoft.com/en-us/dotnet/api/system.environment.specialfolder?view=net-7.0), [Where is |DataDirectory| defined?](https://stackoverflow.com/questions/12187068/where-is-datadirectory-defined), and [ADO.NET |DataDirectory| where is this documented?](https://stackoverflow.com/questions/1409358/ado-net-datadirectory-where-is-this-documented/1409378#1409378) – Tu deschizi eu inchid Sep 02 '23 at 13:51

2 Answers2

0

If you are deploying the database with the application, the proper way to go about this is to add the data file to the project and set its Copy to output directory to Copy if newer, then use "|DataDirectory|" in your connection string as the folder path. That will automatically resolve to the correct folder no matter where the application is deployed as well as when running in the debugger. See www.connectionstrings.com for some examples.

Note that, for most deployed applications, the data directory defaults to the program folder. This means that the advice above is like using Application.StartupPath in a WinForms app but you don't have to use code to set it. If you use ClickOnce deployment then the data directory is managed by ClickOnce and the connection string is resolved automatically still. For Web Forms apps, it resolves to the App_Data folder. Not sure what happens for more modern web apps as I've never tried it.

jmcilhinney
  • 50,448
  • 5
  • 26
  • 46
0

Consider making the connection ODBC rather than native. That would remove the need to manage the physical path to the database. It would also provide more flexibility and cater to future needs such as upgrading the database (for example, from MS Access to SQL Server).

MilletSoftware
  • 3,521
  • 2
  • 12
  • 15