Search code examples
asp.netsql-servermdf

Cannot attach the file *.mdf as database in asp.net


I am trying to attach a *.mdf file to a SQL Server Express version. But I still have a problem with attach and then I removed a database and create a new but same problem when I use Update-Database in Package Manager Console.

My default connection string is:

"DefaultConnection": "Server=(localdb)\\mssqllocaldb;AttachDBFilename=App_Data\\TVK3.mdf;Database=TVK3;Trusted_Connection=true;MultipleActiveResultSets=true;"

I get this error:

Cannot attach the file 'App_Data\TVK3.mdf' as database 'TVK3'.

I searching on google and trying some advice but nothing helped to me. Thank you for any advice.


Solution

  • As davidbaumann said below my posts in comments. When i used absolute filename everythings working good. Thank you.