Click here to Skip to main content
15,888,321 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
C#
I have create Set up file for WPF application and the database is SQLite DB. After the installation the SQLite DB is located this path in C folder, and the application is running properly on any computer that without an administrator Password PC.

C:\Program Files (x86)\myCompany\myScanApp.


C#
public SQLiteConnection dbConnection = new SQLiteConnection(@"Data Source=C:\Program Files (x86)\myCompany\myScanApp\test.s3db;");


C#
The problem is, it is failing to login after running this application if any other administrator password set PC. How can I solve this problem?

How can I access Sqlite DB from C drive after installation WPF application if pc have administrator password ?


What I have tried:

I am using this connection string:-

C#
public SQLiteConnection dbConnection = new SQLiteConnection(@"Data Source=C:\Program Files (x86)\myCompany\myScanApp\test.s3db;");
Posted
Updated 18-Nov-16 9:24am
v2
Comments
Rajesh Kumar 2013 18-Nov-16 13:15pm    
Kindly advise me for a right solutions
[no name] 18-Nov-16 13:33pm    
You need to store your database file somewhere other than "Program files"

1 solution

First, you database should NOT be under Program Files. Everything under Program Files is ReadOnly. I'm guessing that's probably why you think you need admin permissions to run your app. Don't.

The correct solution is to put your database under a more appropriate folder, like C:\ProgramData\company\appName. This location is ReadWrite for everyone. You'll also have to change the connection string to point to it there.
 
Share this answer
 
Comments
Rajesh Kumar 2013 18-Nov-16 23:16pm    
Hello,

How can I create new database path like this: (C:\ProgramData\company\appName\test.s3db) in many other local mechines that run this windows applicaiton using c# code?
Dave Kreskowiak 19-Nov-16 10:04am    
Take a look on your own machine at what's under the path C:\ProgramData. Look at how files and folders are typically arranged in there. Your database file needs to be placed in a known path under this folder that you come up with. Your installer needs to put the database file there.

Once you have that known path, you can build your connection string using a call to Environment.GetFolderPath(SpecialFolder.CommonApplicationData) and Path.Combine(). Read the documentation on both methods to see what they do.

This is very simple string manipulation. You're building a path from a well-known folder, adding the company and appname folder names you came up with, and your database name. That string going into your connection string in code. Again, very simple string manipulation. You can put some replacable tag in your connection string and, after you build the path to the database file, Replace that tag with your file path.

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