Efcore: AttachDBFileName fails if the value includes |DataDirectory|

Created on 9 Sep 2019  路  8Comments  路  Source: dotnet/efcore

I have a WPF Prism application working with Entity Framework Core 2.26. The OnConfiguring method optionsBuilder.UseSqlServer call includes the following in the connect string:
AttachDBFileName=|DataDirectory|\dbfiles\my.mdf;

I created a new project that uses .Net Core 3.0 Preview 9 and Entity Framework Core 3.0 Preview 9. At runtime the same connection string fails. I get a System.ArgumentException with the message "Invalid value for key 'attachdbfilename'."

"|DataDirectory|" appears to be the problem. AttachDBFileName with the full path works fine. If I build up the full path using the value AppDomain.CurrentDomain.BaseDirectory the attach will also work.

closed-external customer-reported

Most helpful comment

My PR to fix this has just been merged, and wil be part of the 1.1 release

All 8 comments

.NET Core SqlClient does not expand DataDirectory?

Yes, if I use "|DataDirectory|" the connection fails.

Do not understand the reason for the closure. Code that worked with .Net, EF Core 2.26 and WPF does not work with .Net Core 3.0 Preview 9, EF Core 3.0 Preview 9 and Wpf. Oh well ...

This is not an issue with EF, but with SqlClient the issue dotnet/SqlClient#16 is tracking the work that needs to be done to fix it.

Please upvote it and subscribe to it for updates.

My PR to fix this has just been merged, and wil be part of the 1.1 release

@ErikEJ Awesome! Really appreciate your perseverance!

Was this page helpful?
0 / 5 - 0 ratings