Reputation: 12688
I've set up the database using these instructions here from MSDN site. Which includes first creating the database and then adding that to the project.
Then in data source when opening the database, I've used something like "Data Source=|Applicatoin Data| + filename.sdf" but when using this, I would launch the app then load some data onto it but then i couldn't see the data in the local database I created outside of my project (as explained in the tutorial I linked to) That would only work if i hardcoded to the .sdf file that was created when I first created the database.
I can't seem to find any information on how to make this a relative path where in between builds the data would stay in the database.
Upvotes: 0
Views: 407
Reputation: 18968
When you build the solution your db is copied to the bin directory
when you debug you use that copy not the one on your project.
This is by design. And it is right.
you should do something like this:
#if DEBUG
public static readonly string ConnectionString =
string.Format(@"Data Source=..\..\DbTest\{0}; password='{1}'", DbFileName, DbPassword);
#else
public static readonly string ConnectionString =
string.Format(@"Data Source=|DataDirectory|\{0}; password='{1}'", DbFileName, DbPassword);
#endif
Remeber to use 2 different dbs:
one for testing one for release app with no data
Upvotes: 1