I want to access a development db at a known location (ie,
"MyApp\MyData\MyDb.mdb") but an unknown machine. I've used
"|DataDirectory|\MyDb.mdb" in app.config with some limited success before
but it's not working out well here.
As a string with substitution variables, the connection (to a legacy MS
Access db w/ security) is basically:
string.Format(@"Provider=Microsoft.Jet.OLEDB.4.0;D ata
Source={1}MyDb.mdb;Jet OLEDB:System Database={1}Security.mdw;User
ID={2};Password={3};",
PROVIDER_JET,
directoryPath,
userID,
password);
I thought I might be able to get what I wanted by IO and reflection easier,
but am stuck. The code below looks like what I want but when I run it from
test code (in a separate assembly) it gives me the path to debug in the Test
assembly (ie "MyApp\Tests\MyData\bin\Debug") instead of the App (ie
"MyApp\MyData\bin\Debug") assembly.
public static string CurrentDevelopmentDirectory() {
var assembly = Assembly.GetAssembly(typeof (Connection)).CodeBase;
return Path.GetDirectoryName(assembly);
}
Thanks for the help! BH