Knight Data Access Layer
Connection String Tags
Basic Tasks C# > Connection Strings > Connection String Tags

The .NET Data Access Layer supports special directories for file based databases. 

 

Tag Replacement Note

%CurrentDirectory%

AppDomain.CurrentDomain.BaseDirectory

https://msdn.microsoft.com/en-us/library/system.appdomain.basedirectory%28v=vs.110%29.aspx

|DataDirectory|

AppDomain.CurrentDomain.GetData("DataDirectory")

http://stackoverflow.com/questions/1409358/ado-net-datadirectory-where-is-this-documented

%ApplicationData%

Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)

http://msdn.microsoft.com/en-us/library/system.environment.specialfolder.aspx

%CommonApplicationData%

Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData)

%LocalApplicationData%

Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)

%MyDocuments%

Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)

%CurrentDriveLetter%

The current drive letter of the 

AppDomain.CurrentDomain.BaseDirectory

 

Example Usage

 

//Setup the provider
SqLiteProvider provider = new SqLiteProvider();
provider.ConnectionString = "Data Source=%LocalApplicationData%\mydb.db;Version=3;"

//Manually instantiate a session
DataHelper db = new DataHelper(provider);