Set DataDirectory manually
From Logic Wiki
Revision as of 08:41, 23 March 2016 by Macrop (Talk) (Created page with "Category:Database Category:SQL Category:CSharp In windows applications, You can manually set your DataDirectory by using '''AppDomain.CurrentDomain.SetData("Dat...")
In windows applications,
You can manually set your DataDirectory by using AppDomain.CurrentDomain.SetData("DataDirectory", path).
You can get the path of your executable by using AppDomain.CurrentDomain.BaseDirectory
Connection String
Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\LocalDbVisTest.mdf;Integrated Security=True
Relative path:
ConnectionString = "Data Source=|DataDirectory|\Database.sdf";
Modifying DataDirectory as executable's path:
string executable = System.Reflection.Assembly.GetExecutingAssembly().Location;
string path = (System.IO.Path.GetDirectoryName(executable));
AppDomain.CurrentDomain.SetData("DataDirectory", path);