Question

I have a c# winforms app that uses SQL compact and here is the connection string for the DB:

<add name="Test.Properties.Settings.TestManagerConnectionString"
            connectionString="Data Source=|DataDirectory|\Database\TestManager.sdf"
            providerName="Microsoft.SqlServerCe.Client.3.5" />

How can I get the path that the connection string is pointing to? ie: C:\Users\name\AppData... etc

Was it helpful?

Solution

Why do you want to move it to a different directory? By default a non-administrative user does not have access to make changes in the Program Files directory tree. AppData is a user specific store that (in the case of network hosted profiles) points to the appropriate directory on the network for the user's app data directory.

If you want to share data for multiple users, there is the All_Users Data Directory. I'm not sure how to specify it with the SqlCE connection string though.

Update

Here is the answer to determining the appdata directory.

To set the DataDirectory property, call the AppDomain.SetData method. If you do not set the DataDirectory property, the following default rules will be applied to access the database folder:

  1. For applications that are put in a folder on the user's computer, the database folder uses the application folder.
  2. For applications that are running under ClickOnce, the database folder uses the specific data folder that is created.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top