开发者

|DataDirectory| in Project properties > Settings

开发者 https://www.devze.com 2023-03-23 00:41 出处:网络
The connection string setting is below: Name: dbPersonConnectionString Type: Connection string Scope: Application

The connection string setting is below:

Name: dbPersonConnectionString

Type: Connection string Scope: Application

Value: Data Source=|D开发者_StackOverflowataDirectory|\dbPerson.sdf

When I install & run the application, it looks for DB in C:\MyApp\Data\ folder. It should be C:\MyApp without additional \Data folder.

Should I simply create Data folder in my project and move DB files under that folder or I simply adjust |DataDirectory| -and how-?

EDIT:

        string executable = System.Reflection.Assembly.GetExecutingAssembly().Location;
        string path = (System.IO.Path.GetDirectoryName(executable));
        AppDomain.CurrentDomain.SetData("DataDirectory",path);


This has been asked before. This MSDN post gives a good overview.

It should indeed default to your binaries folder, you can change it with AppDomain.SetData() . If you change it, better do it early.


AppDomain.CurrentDomain.SetData("DataDirectory", Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location));

This should work always because Directory.GetCurrentDirectory() may return other directory than the executable one


This one solved my problem

AppDomain.CurrentDomain.SetData("DataDirectory", Directory.GetCurrentDirectory());
0

精彩评论

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