sqlserver compact sdf, sqlite 数据库 在net中相对路径设置方法 - 摘自网络
You should use:
Data Source=|DataDirectory|\MyDb.sdf
|DataDirectory| points to the App_Data folder.
在程序启动时,设置AppDomain.CurrentDomain.setData(“DataDirectory”,我的目录字符串);Winform的程序那当然是在Main函数中了,废话不说了,我的代码如下
string p = AppDomain.CurrentDomain.BaseDirectory;
if (p.IndexOf("\\bin\\") > 0)
{
if (p.EndsWith("\\bin\\Debug\\"))
p = p.Replace("\\bin\\Debug", "");
if (p.EndsWith("\\bin\\Release\\"))
p = p.Replace("\\bin\\Release", "");
}
if (!p.EndsWith("App_Data\\"))
p = p + "App_Data\\";
AppDomain.CurrentDomain.SetData("DataDirectory", p);思想就是去掉调试期间和生产期间的不同,这样要注意的是,发布程序的时候,数据库也要放到App_Data目录下面。


浙公网安备 33010602011771号