I write a WPF program which uses LocalDb. The program worked perfectly with |DataDirectory|
.
var sqlConnectionStringBuilder = new SqlConnectionStringBuilder
{
DataSource = @"(LocalDB)\MSSQLLocalDB",
AttachDBFilename = $"|DataDirectory|\\Lc Db {userName}.mdf",
IntegratedSecurity = true
};
I upgraded from .net46 to .net5 but I still use EF and not EF.Core. Now I got this exception when reaching for the db at the first time: Invalid value for key 'attachdbfilename'
. If I use absolute path then I can reach the Db.
var sqlConnectionStringBuilder = new SqlConnectionStringBuilder
{
DataSource = @"(LocalDB)\MSSQLLocalDB",
AttachDBFilename = $"AttachDBFilename = @"c:\Users\xyz\Documents\LedgerCommander\LedgerCommander\bin\Debug\net5.0-windows\Lc Db Heckl.mdf"",
IntegratedSecurity = true
};
How should I use |DataDirectory|
in .net core? I tried a number of approach without success. 1, 2, 3, 4