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

|DataDirectory| does not come from config settings; you’re mixing up three different things: ConfigurationManager.AppSettings[“DataDirectory”] This comes from config settings; a .config file you have to create and put into your project. This particular setting is the value of the element with key “DataDirectory” in the AppSettings element. This doesn’t exist unless you put one in … Read more

ADO.NET |DataDirectory| where is this documented?

|DataDirectory| is a substitution string so you can configure the location of your database file separately. So instead of: SqlConnection c = new SqlConnection ( @”Data Source=.\SQLDB; AttachDbFilename=C:\MyDB\Database.mdf;Initial Catalog=Master”); you do the following: // Set |DataDirectory| value AppDomain.CurrentDomain.SetData(“DataDirectory”, “C:\myDB”); // SQL Connection String with |DataDirectory| substitution string SqlConnection c = new SqlConnection ( @”Data Source=.\SQLDB; … Read more