I manage to finish my project and publish it for deployment on other machines. My C# WPF application have SQL Server CE as its backend database. I wanted the database to be able to work in other machine that have no SQL Server CE installed. I publish it using clickonce, the publish was successful. However when I run it on other machines, and tries to open the database there is an error prompt that said 'database file cannot be found. Check the path to the database [Data Source=D:db.sdf]. I followed the tutorials on clickonce by mdsn, Microsoft and by other people, the result is always the same. The local database cannot be detected.
Add a comment
|
1 Answer
D:db.sdf is not created by ClickOnce, you must have changed something. ClickOnce by default installs data that is included in a project to a directory in the app folder, and sets the DataDirectory app domain value to the path to this directory. In your application you should use something like
SqlConnection("Data Source=|DataDirectory|db.sdf;...")
Note that DataDirectory may not be writable by users. If you want users to save data you should copy |DataDirectory|db.sdf to some place writable like
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)