开发者

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"));
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜