Michael Puckett II
Michael Puckett II

Reputation: 6749

WPF Desktop Application with MDF used locally for all local users

I am using Visual Studio 2013. I have all components installed on my machine needed to run this application I am questioning. I have not completed the application to deploy for testing but some questions arose before completion that I need addressed now; to prevent overhauling later.

Here's how it should work when deployed to clients.

Client installs application which runs on desktop not windows store in WPF. The application is per user and runs for all users on the local machine. Each user needs to read and write data to a database file but it needs to be the same MDF being used. Therefore each process of the application, no matter the user session, on the same machine, all interact with the same database / same data.

Question: When adding the database to the project where will it be installed by default? In the applications program folder along with program? If so what restrictions exist to read/write to the database and are there any? I have added no extra security on my side. The info isn't private or critical.

Question: Would end users need to install any sort of SQL in order for the application to do this? If so I can package it with the install but this seems like alot of overhead during install.

If the MDF is installed per user how do I change this to install it once for all users?

Before saying so, yes this needs to be a database and not a file. Reasons I need not describe. I have considered alternative but this is by far the best solution so please no alternatives.

Upvotes: 1

Views: 1341

Answers (1)

Vojtěch Dohnal
Vojtěch Dohnal

Reputation: 8102

When you add mdf file to your project and set properly the value of Copy to Output Directory, it will be copied to the bin directory of your project whenever you build the project. When you create setup project for your app project, it will be by default copied to the folder where your app is installed. You can either specify different location in your setup project or copy the file to the desired location during the first run of your app.

There are several suitable folders in Windows, one possible choice is %PROGRAMDATA% C:\ProgramData folder, but it is by default read only for non-admin users. If you do not worry about security, go for %PUBLIC% C:\Users\Public. It is completely accessible for all users within interactive group.

I recommend to package LocalDB with your project. It can be installed silently with one line of code, though only with admin privileges. For non-admin click-once install you would have to use SQL CE, which is quite different and uses sdf files.

I think you should do it this way: include a seed database MDF file in the application and copy it to a %PUBLIC%\YourApp folder when the application first launches. Optionally include LocalDB install in your setup project.

Upvotes: 2

Related Questions