SQLCe local db in temp- path in connectionstring?
I have SQL Ce db in my app, which is included in my app directory. While debugging its OK, but when published and run with setup.exe, it retrieves "file not found" in temporary directory the app is ran from. I would like to run from standard location, but I dont know how to change it.
I am using this string:
SqlCeCo开发者_Python百科nnection connection = new SqlCeConnection("Data Source=database.sdf;Persist Security Info=False;");
When I run setup.exe, the app never starts, stating that in its temporary directory the db file was not found. When I run app.exe, it works. I do not understand it...:(
EDIT: I can see that in the VS project settings, there is connection string and there is "Data Source=|DataDirectory|\Database.sdf"
The path should be something like local directory? Thanks!
Build your connection string dynamically. Something like this:
string connString = string.Format("Data Source={0}; Persist Security Info=False;",
Path.Combine(Application.StartupPath, "database.sdf"));
精彩评论