[软件设计/软件工程] NET中SQLSERVER COMPACT SDF、SQLITE数据库相对路径设置方法

[复制链接]
发表于 2022-5-2 11:32:03
You should use:
Data Source=|DataDirectory|\MyDb.sdf
|DataDirectory| points to the App_Data folder.

程序启动时,设置 AppDomain.CurrentDomain.setData("DataDirectory", my directory string); 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目录下。

(You should use:
Data Source=|DataDirectory|\MyDb. sdf
|DataDirectory| points to the App_ Data folder.
When the program starts, set AppDomain CurrentDomain. setData("DataDirectory", my directory string);  Of course, the program of WinForm is in the main function. No nonsense. My code is as follows
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);
The idea is to remove the difference between debugging period and production period, so it should be noted that when the program is released, the database should also be placed in app_ Data directory.
)





上一篇:JAVASCRIPT 中的 SETATTRIBUTE 用法
下一篇:解决数据库 TABLE 'CONTENT_TAGS' IS MARKED A

使用道具 举报

Archiver|手机版|小黑屋|吾爱开源 |网站地图

Copyright 2011 - 2012 Lnqq.NET.All Rights Reserved( ICP备案粤ICP备14042591号-1粤ICP14042591号 )

关于本站 - 版权申明 - 侵删联系 - Ln Studio! - 广告联系

本站资源来自互联网,仅供用户测试使用,相关版权归原作者所有

快速回复 返回顶部 返回列表