| DataDirectory目录|在项目性状>设置 [英] |DataDirectory| in Project properties > Settings
问题描述
连接字符串设置如下:
名称:
dbPersonConnectionString
输入:
连接字符串
适用范围:
应用
价值:
数据源= | DataDirectory目录| \dbPerson.sdf
块引用>
当我安装和放大器;运行应用程序,它会查找DB在C:\MyApp\Data\文件夹中。它应该是C:\MyApp无需额外\Data文件夹
如果我只是在我的项目创造Data文件夹,这个文件夹下移动数据库文件或我简单地调整| DataDirectory目录| ?-and如何 -
编辑:
字符串可执行=系统。.Reflection.Assembly.GetExecutingAssembly()的位置;
路径字符串=(System.IO.Path.GetDirectoryName(可执行文件));
AppDomain.CurrentDomain.SetData(DataDirectory目录,路径);
解决方案这已经被问了。这 MSDN后给出了一个很好的概述。
这的确应该默认为您的二进制文件的文件夹,你可以用
更改AppDomain.SetData()
。如果你改变它,更好地做到这一点早。The connection string setting is below:
Name: dbPersonConnectionString
Type: Connection string Scope: Application
Value: Data Source=|DataDirectory|\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.这篇关于| DataDirectory目录|在项目性状>设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!