关于数据库连接串中的DataDirectory的官方说明

Full path vs relative path

One of the reasons why it was hard to work with database files before is that the full path to the database was serialized in different places. This made it harder to share a project and also to deploy the application. In this version, the .NET runtime added support for what we call the DataDirectory macro. This allows Visual Studio to put a special variable in the connection string that will be expanded at run-time. So instead of having a connection string like this:

"Data Source=.\SQLExpress;AttachDbFileName=c:\program files\app\data.mdf"

You can have a connection string like this:

"Data Source=.\SQLExpress;AttachDbFileName=|DataDirectory|\data.mdf"

This connection string syntax is supported by the SqlClient and OleDb managed providers.

By default, the |DataDirectory| variable will be expanded as follow:

- For applications placed in a directory on the user machine, this will be the app‘s (.exe) folder.
      - For apps running under ClickOnce, this will be a special data folder created by ClickOnce
      - For Web apps, this will be the App_Data folder

Under the hood, the value for |DataDirectory| simply comes from a property on the app domain. It is possible to change that value and override the default behavior by doing this:

AppDomain.CurrentDomain.SetData("DataDirectory", newpath)

https://blogs.msdn.microsoft.com/smartclientdata/2005/08/26/working-with-local-databases/

原文地址:https://www.cnblogs.com/woolhoo/p/8683094.html

时间: 2024-08-30 08:09:13

关于数据库连接串中的DataDirectory的官方说明的相关文章

.net 各种数据库连接串大全

数据库的连接串 在数据库的各种应用程序开发中,连接数据库是数据库应用程序开发的第一步,同时也是最重要的一步. 而数据库连接字符串的拼写主要取决于4个条件: 连接的数据库的类型:SQL Server,Oracle,MySQL,Acess,MogoDB,Visual FoxPro(dBASE),Excel 数据库访问接口类型:ODBC,OLE DB 连接的模式:标准连接(Standard Security),信任连接(Trusted connection) 连接方式:TCP/IP,Named Pip

浅谈数据结构之KMP(串中的模式匹配算法)

KMP算法是一种模式匹配算法的改进版,其通过减少匹配的次数以及使主串不回朔来减少字符串匹配的次数,从而较少算法的相应代价,但是,事件万物是普遍归中的,KMP算法的有效性也是有一定的局限的,我将在本文的最后也讨论这个算法的局限性. 一般的匹配算法: KMP基本概念引入: 但是,其实我们会发现,上面的中间两个匹配步骤是没有必要的,因为他们的第一个匹配字母就不相同,完全没有可比性,而当我们在第四次匹配的时候,其实我们从模式串中就可得知,只有当模式串滑到这个地方的时候,它的匹配才是最有价值的,因为从模式

hdu5384 AC自动机模板题,统计模式串在给定串中出现的个数

http://acm.hdu.edu.cn/showproblem.php?pid=5384 Problem Description Danganronpa is a video game franchise created and developed by Spike Chunsoft, the series' name is compounded from the Japanese words for "bullet" (dangan) and "refutation&q

LeetCode Reverse Words in a String 将串中的字翻转

1 class Solution { 2 public: 3 void reverseWords(string &s) { 4 string end="",tem=""; 5 char *p=&s[0]; 6 while(*p!='\0'){ 7 while(*p==' ') //过滤多余的空格,针对串头 8 p++; 9 while(*p!=' '&&*p!='\0'){ //积累一个单词,存于临时串 10 tem=tem+*p;

java 11-8 在大串中查找小串的案例

1.统计大串中小串出现的次数 举例: 在字符串"woaijavawozhenaijavawozhendeaijavawozhendehenaijavaxinbuxinwoaijavagun" 结果: java出现了5次 分析: 1.首先已经知道字符串 A:定义一个统计变量=0: B:在大串中查找小串是否存在,用 int indexOf(String str):返回指定字符在此字符串中第一次出现处的索引. a:如果返回的索引值是-1,则说明 大串中并不存在这个小串,输出统计变量 b:返回

计算子串在主串中的位置及其优化(KMP算法)

问题描述:设置一个起始位置,寻找主串中第一次出现子串的首位置. 算法实现: int index(string str,string substr,int pos) { int i=0,j=0; int slen,sslen; i=pos; slen=str.length(); sslen=substr.length(); while(i+sslen<slen) { while(j<sslen) { if(str[i+j]==substr[j]) j++; else break; } if(j=

(hdu step 4.1.5)find the nth digit(求S串中的第n个位置上是什么数字)

题目: find the nth digit Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 689 Accepted Submission(s): 244   Problem Description 假设:S1 = 1S2 = 12S3 = 123S4 = 1234.........S9 = 123456789S10 = 123456789

HDU 6153 A Secret 套路,求解前缀在本串中出现的次数

http://acm.hdu.edu.cn/showproblem.php?pid=6153 首先相当于翻转两个串,然后求s2前缀在s1中出现的次数. 这是一个套路啦 首先把两个串结合起来,中间加一个'%'之类的分割 设dp[i]表示前缀1---i在本串中的出现次数和 那么从后开始dp,所有dp值一开始都是1,表示前缀出现了一次,就是自己本身. 转移,设当前去到第i位,则dp[next[i + 1] - 1] += dp[i] 就是ABACABA这样,已经知道了ABACABA出现了一次,然后前后

删除模式串中出现的字符

删除模式串中出现的字符,如"welcome to asted",模式串为"aeiou"那么得到的是"wlcm t std". #include<iostream> #include<cstring> using namespace std; char *re(char *str,char *model) { if(str==NULL||model==NULL) return NULL; int Hash[26]={0};