SQLCe local db in temp-path in connection string?

I have a SQL Ce db in my application that is included in my application directory. Debugging it is OK, but when it is published and run with setup.exe, it extracts the "file not found" in the temp directory from which the application is launched. I would like to run from a standard location, but I don't know how to change it.

I am using this line:

SqlCeConnection connection = new SqlCeConnection("Data Source=database.sdf;Persist Security Info=False;");

      

When I run setup.exe the application never starts, stating that no db file was found in the temp directory. When I run app.exe it works. I do not understand this...: (

EDIT: I see there is a connection string in the VS project settings and there is "Data Source = | DataDirectory | \ Database.sdf"

The path should be something like a local directory? Thank!

+2


source to share


1 answer


Build your connection string dynamically. Something like that:



string connString = string.Format("Data Source={0}; Persist Security Info=False;",
    Path.Combine(Application.StartupPath, "database.sdf"));

      

+1


source







All Articles