1

When I use a relative path (AttachDbFilename=|DataDirectory|\Database1.mdf;) in my connection string Database.Delete() gives me

InvalidOperationException : Unable to delete the database. There is no database that corresponds to the given AttachDBFileName.

When using an absolute path deleting works. I know that my relative path is correct because other database operations work with it too.

I thought not being able to use a relative path with super directories (\..\) was the only limitation?

I'm using Entity Framework 6.1.1 and LocalDB.

user764754
  • 3,865
  • 2
  • 39
  • 55

1 Answers1

2

Using the solution from this answer solved the problem for me:

AppDomain.CurrentDomain.SetData("DataDirectory", Path.Combine(AppDomain.CurrentDomain.BaseDirectory, ""));
Community
  • 1
  • 1
Matthijs Wessels
  • 6,530
  • 8
  • 60
  • 103