0

net project as well as a setup project. I also have it so that during installation it asks the users to enter a file location to store their database. the plan is to have an empty .mdf file, with all the tables setup, copied into that folder and I store the folder path in a config file.

this is mainly because I am planning on having multiple separate applications that all need the ability to access the same database. I have it storing the folder path in my config file the only thing I'm having trouble with is

  1. storing the template files I don't know if i should do this in the setup project or main project
  2. how to copy said template files into a new folder

so far I have been unable to find a solution so any help is appreciated

Lucent
  • 3
  • 3
  • Not sure what these template files are or how you intend to use them so don't know if can give any advice on that. Question aside though, you could always use the build in folder structures and save the whole complication of user defined paths. Read over https://learn.microsoft.com/en-us/dotnet/api/system.environment.specialfolder?view=net-7.0. Final thing to add, I would be incredibly weary of using an Access db where there is potential for simultaneous connections. Many RDMS do a better job in multi-user enviroments – Hursey Dec 19 '22 at 19:33
  • Have a look in the NuGet packages. There are several libraries that can do that for you. – Julian Dec 20 '22 at 12:07
  • Thank you for the resources and advice. ill also check out the NuGet package – Lucent Dec 20 '22 at 19:50

1 Answers1

0

Well here is what I do this in a few of my projects - something that has proven reliable enough for me over the years (which you may or may want to do as well):

I have the program itself create the database files in an initialization routine. First however, it creates the sub folders in which the database files will be stored, if they don't already exist.

To do this, the program just checks if the folder exists and if the database file exists and if they do not, it creates them on the spot:

If Directory.Exists(gSQLDatabasePathName) Then

Else

  Directory.CreateDirectory(gSQLDatabasePathName)

End If
 
If File.Exists(gSQLiteFullDatabaseName) Then

Else

   ...

I also have the program do some other stuff in the initialization routine, like creating an encryption key to be used when storing / retrieving the data - but that may be more than you need (also, for full disclosure, this has some rare issues that I haven't been able to pin down).

Here too are some addition considerations:

I appreciate you have said that you want to give the user the choice of where to store their database files. However, I would suggest storing them in the standard locations Where is the correct place to store my application specific data? and only allowing the users to move them if the really need to (for example if the database needs to be shared over the network) as it will make the support of your app harder if every user has their data stored in different places.

I have found letting the user see in their options/settings windows where their database is stored is a good idea.

Also to encourage them to back those files /directories up.

Also to create automatic backups of several generations for the user.

Hope this helps.

Rob
  • 3,488
  • 3
  • 32
  • 27