Click here to Skip to main content
16,019,152 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello everyone,

I want advice . I have created an WPF windows application. And the database is SQLite DB. After installation then db was located this path
@"C:\Program Files (x86)\customercompanyname\appname\mydb.s3db"; then trying to open application in some other local machine if occurred error if the machine set administrator privilege. So I have change the db access path using c# code like shown below.

What I have tried:

C#
string path = "C" + ":\\MyDBFolder";
            if (!Directory.Exists(path))
            {
		 string sourceDirectory = @"C:\Program Files (x86)\customercompanyname\appname\mydb.s3db";
		  string targetDirectory = path + "\\mydb.s3db";
              File.Copy(sourceDirectory, targetDirectory, true);
		 }


After, now the apps working fine every local machine. But problem is, the customer demanding me, they want to set like no one can not show or access (like delete, move folder etc.) the DB folder. Only the apps can access it. So please advise me, how can I solve handle this challenge?
Posted
Comments
[no name] 19-Jan-17 9:45am    
Why are you hardcoding paths in your application to begin with?
Member 12955507 19-Jan-17 10:35am    
@NotPolitcallyCorrect : I am copying path inside App.xaml.cs
Richard Deeming 19-Jan-17 11:00am    
If the user running your application doesn't have access to modify the file, then your application doesn't have access to modify the file.

Conversely, if your application has access to modify the file, then the user has access to modify the file.

With a local file-based database, the best you can do is to "hide" the file in a folder that the user probably won't see - for example, in an application-specific folder under the C:\ProgramData\ folder. However, it won't stop them from modifying it if they manage to find the file.

To properly secure the database, you would need to use a real database server like SQL Server.
Member 12955507 19-Jan-17 11:09am    
@Richard Deeming, Now I am hiding the folder this path @"C:\MyDBFolder with sqlite db. You are advice me, I have to keep the db inside programdata\MyDBFolder\DB in hide format. Am I right?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900