Efcore: ArgumentException: Invalid value for key 'attachdbfilename'.

Created on 27 Oct 2018  路  8Comments  路  Source: dotnet/efcore

I try to use app_data dynamic attached database. As I can see from source code should be supported? Attachdbfilename with DataDirectory?

Visual Studio ASP.NET core Project EF 2.1 (actual)
appsettings.json
"ConnectionString1": "Data Source=(localdb)\mssqllocaldb;AttachDbFilename=|DataDirectory|\rechnung.mdf;Integrated Security=True; MultipleActiveResultSets=True"

Startup.cs Startup
string appRoot = Directory.GetCurrentDirectory();
AppDomain.CurrentDomain.SetData("DataDirectory", Path.Combine(appRoot, "App_Data"));

configureservice
.AddDbContext(options =>
options.UseSqlServer(
Configuration.GetConnectionString("ConnectionString1"))
);

Modelclass constructor
public ModelRechnung(DbContextOptions options):base(options)

Exception on program.cs
ArgumentException: Invalid value for key 'attachdbfilename'.

at
var context = services.GetRequiredService();
context.Database.EnsureCreated();

closed-external customer-reported

Most helpful comment

Dupe of dotnet/corefx#19492

All 8 comments

Maybe it only works with full .net framework?

      Maybe it only works with full .net framework?

I am really curios you are answering "Maybe" and have no glue

look at https://github.com/aspnet/EntityFrameworkCore/blob/a588722e10f34a12b9cea3d655fd26aafd91051b/src/EFCore.SqlServer/Migrations/SqlServerMigrationsSqlGenerator.cs#L669-L685

Dupe of dotnet/corefx#19492

@bricelam sure? what is the function ExpandFileName in the sqlserver lib code, shown before?
I tried to get the step into F11 debugging working, to see what really happens at ensurecreated, but didnt work for me.
A overall issue is, keep versioning in track and changes. Works not in 2.0 can be solved in 2.1, who knows.

That code is so EF Core can handle |DataDirectory| when creating the database. SqlClient will also need to handle it when connecting to the database.

In other words, the EF code works as expected on .NET Framework, but SqlClient fails on .NET Core before that EF code has a chance to run.

I am not a Github Guru, but is that issue a corefx issue? I would expect as EF SQLClient issue?

SqlClient is a CoreFx property, not owned by the EF team

Was this page helpful?
0 / 5 - 0 ratings