ef6: Update-Database fails creating a database with mssqllocaldb
Dear Maintainer,
Update-Database fails creating a database with mssqllocaldb when using the default App.config I receive the following error: CREATE FILE encountered operating system error 5(Access is denied.) while attempting to open or create the physical file ‘C:\Users\[Username][Projectname].[Contextclass].mdf’.
It looks like it is missing a '\' between the username and the projectname.
Is this database location assigned by SQL Server LocalDb or is this a problem in ‘System.Data.Entity.Infrastructure.LocalDbConnectionFactory’?
Thank you in advance.
Best regards,
NiekGr
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 15
- Comments: 24 (7 by maintainers)
Installing and applying the latest SQL Server 2017 CU is probably the simplest cure.
Seems related to conflicting version of SQLLocalDB. Visual Studio comes with version 2016. The problem occurs when you have installed version 2017. To resolve the problem follow these steps:
EntityFrameWork migraton will now succeed (slash is added to the path)
Surprised to see this bug is still there as of now, using localdb.
I got the same issue, but with EF Core, and only with localdb (Regular SQL Server Express works fine)
My windows username nemke is concatenated with database name nemkeaspnet-WebApplication1-083FBAB5-A996-467F-8312-ACEEC24C3A0C.mdf
It seems like this is a problem with localdb v14 https://dba.stackexchange.com/questions/191393/localdb-v14-creates-wrong-path-for-mdf-files http://answers.flyppdevportal.com/MVC/Post/Thread/f332e6e4-ed6d-4a9e-b8a6-a04bdfd64630?category=sqldatabaseengine
Fixed in latest SQL Server 2017 CU!
@ErikEJ But it is more than 800 MB, the total LocalDB 2017 is just below 50 MB. Is there a better way to fix such a tiny bug from microsoft?!
Applied last SQL Server 2017 CU but this doesn’t fix the problem: “CREATE FILE encountered operating system error 5(Toegang geweigerd.) while attempting to open or create the physical file ‘C:\Users[username]MvcMovieContext-94a57038-3170-497a-b0f0-b7cf52e78fec.mdf’. CREATE DATABASE failed. Some file names listed could not be created. Check related errors.”
Username is still missing ‘\’
Today, I confirmed that you don’t even need EF to repro this issue, and we have reported this to the SQL Server team. The saving grace of this is that Visual Studio 2017 still installs the SQL Server 2016 version of LocalDB.
Given all this, at this point we don’t plan to make any code changes in EF Core or EF6 to try to compensate for the SQL Server bug.
Here are repro steps without EF:
Expected result:
The database Hello is created.
Actual result:
We had the same issue. Created the database manually and got Update-Database initialize it. That resolved our problem but the root cause must be addressed anyway.
same problem when running Update-Database i got this messag, am running a SQL server 2017 any help guys?
@ErikEJ what’s the best way to fix this problem? I’m still having customers hit it. See https://github.com/aspnet/Docs/issues/7599
Same here guys, will try creating the database manually as a workaround.