|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:MyDBDatabase.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; AttachDbFilename=|DataDirectory|Database.mdf;Initial Catalog=Master");
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…