EF appears to be trying to create a database file in the wrong location.
Exception message: CREATE FILE encountered operating system error 5(Access is denied.) while attempting to open or create the physical file 'C:\Users\DazDennis.mdf'.
CREATE DATABASE failed. Some file names listed could not be created. Check related errors.
Stack trace:
> Error Number:5123,State:1,Class:16
Failed executing DbCommand (6ms) [Parameters=[], CommandType='Text', CommandTimeout='60']
CREATE DATABASE [Dennis];
System.Data.SqlClient.SqlException (0x80131904): CREATE FILE encountered operating system error 5(Access is denied.) while attempting to open or create the physical file 'C:\Users\DazDennis.mdf'.
CREATE DATABASE failed. Some file names listed could not be created. Check related errors.
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
at System.Data.SqlClient.SqlCommand.RunExecuteNonQueryTds(String methodName, Boolean async, Int32 timeout, Boolean asyncWrite)
at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource`1 completion, Boolean sendToPipe, Int32 timeout, Boolean asyncWrite, String methodName)
at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
at Microsoft.EntityFrameworkCore.Storage.Internal.RelationalCommand.Execute(IRelationalConnection connection, DbCommandMethod executeMethod, IReadOnlyDictionary`2 parameterValues)
at Microsoft.EntityFrameworkCore.Storage.Internal.RelationalCommand.ExecuteNonQuery(IRelationalConnection connection, IReadOnlyDictionary`2 parameterValues)
at Microsoft.EntityFrameworkCore.Migrations.MigrationCommand.ExecuteNonQuery(IRelationalConnection connection, IReadOnlyDictionary`2 parameterValues)
at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationCommandExecutor.ExecuteNonQuery(IEnumerable`1 migrationCommands, IRelationalConnection connection)
at Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerDatabaseCreator.Create()
at Microsoft.EntityFrameworkCore.Migrations.Internal.Migrator.Migrate(String targetMigration)
at Microsoft.EntityFrameworkCore.Design.Internal.MigrationsOperations.UpdateDatabase(String targetMigration, String contextType)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.UpdateDatabase.<>c__DisplayClass0_1.<.ctor>b__0()
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
ClientConnectionId:6780d595-23b6-4c79-abdd-d318f348268d
Error Number:5123,State:1,Class:16
CREATE FILE encountered operating system error 5(Access is denied.) while attempting to open or create the physical file 'C:\Users\DazDennis.mdf'.
CREATE DATABASE failed. Some file names listed could not be created. Check related errors.
Use this connection string in appsettings:
"Server=(localdb)\\mssqllocaldb;Database=Dennis;Trusted_Connection=True;MultipleActiveResultSets=true"
Make sure no database already exists on localdb.
dotnet ef database update.EF tries to create the new database as C:/Users/[UserName][DatabaseName] which fails due to access rights - I would expect it should be creating it at C:/Users/[UserName]/[DatabaseName]
EF Core version:
<PackageReference Include="Microsoft.AspNetCore.App" Version="2.1.2" />
Database Provider: (e.g. Microsoft.EntityFrameworkCore.SqlServer)
services.AddDbContext<FooDbContext>(options =>
{
options.UseSqlServer(
Configuration.GetConnectionString("DefaultConnection"));
Operating system: Windows 10
IDE: Visual Studio 2017 15..8.3
Duplicate, patch your LocalDB 2017 with the latest CU
@ErikEJ - thanks - any idea how do I do that? I found a SQL 2017 CU but when I run it there is no mention of LocalDb so it makes me wonder If I have the right update:

Nevermind - looks like I had found the correct one :-)
For anyone else looking: https://www.microsoft.com/en-us/download/details.aspx?id=56128

LocalDB = SQL Server Express LocalDB
Most helpful comment
LocalDB = SQL Server Express LocalDB