天道酬勤,学无止境

datadirectory

How do I read the current path of |DataDirectory| from config settings

I'm writing a program that requires the user to select the active database at application startup. I have a Windows Form that will list the databases stored in a sub-folder of ApplicationData specifically for storing the database files. When I create a new database, however, I need to copy the the template database, but can't figure out where it's stored by default. I've tried: dpath = ConfigurationManager.AppSettings["DataDirectory"]; I always seem to get a null value in return though. At one point I gave up and figured I could just set the DataDirectory to a folder of my choice, but it seems

2021-03-30 02:29:19    分类:问答    c#   sql-server-ce   datadirectory

ADO.NET | DataDirectory | 这在哪里记录?(ADO.NET |DataDirectory| where is this documented?)

问题 在AppConfig中,可以使用|DataDirectory| 但我找不到任何文档? 回答1 |DataDirectory| 是替换字符串,因此您可以单独配置数据库文件的位置。 因此,而不是: SqlConnection c = new SqlConnection ( @"Data Source=.\SQLDB; AttachDbFilename=C:\MyDB\Database.mdf;Initial Catalog=Master"); 您可以执行以下操作: // Set |DataDirectory| value AppDomain.CurrentDomain.SetData("DataDirectory", "C:\myDB"); // SQL Connection String with |DataDirectory| substitution string SqlConnection c = new SqlConnection ( @"Data Source=.\SQLDB; AttachDbFilename=|DataDirectory|\Database.mdf;Initial Catalog=Master"); 回答2 在MSDN社交论坛中,可以找到此答案 | DataDirectory | (用管道符号括起来)是一个替换字符串,它指示数据库的路径。

2021-03-26 13:13:09    分类:技术分享    c#   ado.net   datadirectory