none
EF Core 2 не может создать БД - отказано в доступе Windows RRS feed

  • Вопрос

  • Добрый вечер!

    При выполнении команды dotnet ef database update получаю ошибку: 

    PS C:\beginners.webapi\beginners.webapi> dotnet ef database update -v
    Using project 'C:\beginners.webapi\beginners.webapi\beginners.webapi.csproj'.
    Using startup project 'C:\beginners.webapi\beginners.webapi\beginners.webapi.csproj'.
    Writing 'C:\beginners.webapi\beginners.webapi\obj\beginners.webapi.csproj.EntityFrameworkCore.targets'...
    dotnet msbuild /target:GetEFProjectMetadata "/property:EFProjectMetadataFile=C:\Users\Ivan Ivanov\AppData\Local\Temp\tmpF2B3.tmp" /verbosity:quiet /nologo C:\beginners.webapi\beginners.webapi\beginners.webapi.csproj
    Writing 'C:\beginners.webapi\beginners.webapi\obj\beginners.webapi.csproj.EntityFrameworkCore.targets'...
    dotnet msbuild /target:GetEFProjectMetadata "/property:EFProjectMetadataFile=C:\Users\Ivan Ivanov\AppData\Local\Temp\tmpF796.tmp" /verbosity:quiet /nologo C:\beginners.webapi\beginners.webapi\beginners.webapi.csproj
    dotnet build C:\beginners.webapi\beginners.webapi\beginners.webapi.csproj /verbosity:quiet /nologo
    Сборка успешно завершена.
        Предупреждений: 0
        Ошибок: 0

    Прошло времени 00:00:01.65
    dotnet exec --depsfile C:\beginners.webapi\beginners.webapi\bin\Debug\netcoreapp2.1\beginners.webapi.deps.json --additionalprobingpath "C:\Users\Ivan Ivanov\.nuget\packages" --additionalprobingpath "C:\Program Files\dotnet\sdk\NuGetFallbackFolder" --runtimeconfig C:\beginners.webapi\beginners.webapi\bin\Debug\netcoreapp2.1\beginners.webapi.runtimeconfig.json "C:\Program Files\dotnet\sdk\2.1.403\DotnetTools\dotnet-ef\2.1.4\tools\netcoreapp2.1\any\tools\netcoreapp2.0\any\ef.dll" database update --assembly C:\beginners.webapi\beginners.webapi\bin\Debug\netcoreapp2.1\beginners.webapi.dll --startup-assembly C:\beginners.webapi\beginners.webapi\bin\Debug\netcoreapp2.1\beginners.webapi.dll --project-dir C:\beginners.webapi\beginners.webapi\ --language C# --working-dir C:\beginners.webapi\beginners.webapi --verbose --root-namespace beginners.webapi
    Using assembly 'beginners.webapi'.
    Using startup assembly 'beginners.webapi'.
    Using application base 'C:\beginners.webapi\beginners.webapi\bin\Debug\netcoreapp2.1'.
    Using working directory 'C:\beginners.webapi\beginners.webapi'.
    Using root namespace 'beginners.webapi'.
    Using project directory 'C:\beginners.webapi\beginners.webapi\'.
    Finding DbContext classes...
    Finding IDesignTimeDbContextFactory implementations...
    Finding application service provider...
    Finding IWebHost accessor...
    Using environment 'Development'.
    Using application service provider from IWebHost accessor on 'Program'.
    Found DbContext 'SqlDbContext'.
    Finding DbContext classes in the project...
    Using context 'SqlDbContext'.
    info: Microsoft.EntityFrameworkCore.Infrastructure[10403]
          Entity Framework Core 2.1.4-rtm-31024 initialized 'SqlDbContext' using provider 'Microsoft.EntityFrameworkCore.SqlServer' with options: None
    Finding design-time services for provider 'Microsoft.EntityFrameworkCore.SqlServer'...
    Using design-time services from provider 'Microsoft.EntityFrameworkCore.SqlServer'.
    Finding design-time services referenced by assembly 'beginners.webapi'.
    No referenced design-time services were found.
    Finding IDesignTimeServices implementations in assembly 'beginners.webapi'...
    No design-time services were found.
    fail: Microsoft.EntityFrameworkCore.Database.Command[20102]
          Failed executing DbCommand (8ms) [Parameters=[], CommandType='Text', CommandTimeout='60']
          CREATE DATABASE [BookstoreDb];
    System.Data.SqlClient.SqlException (0x80131904): CREATE FILE encountered operating system error 5(Отказано в доступе.) while attempting to open or create the physical file 'C:\Users\Ivan IvanovBookstoreDb.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)
    ClientConnectionId:67902115-088f-4408-907b-f0fd4ed7a14d
    Error Number:5123,State:1,Class:16
    Failed executing DbCommand (8ms) [Parameters=[], CommandType='Text', CommandTimeout='60']
    CREATE DATABASE [BookstoreDb];
    System.Data.SqlClient.SqlException (0x80131904): CREATE FILE encountered operating system error 5(Отказано в доступе.) while attempting to open or create the physical file 'C:\Users\Ivan IvanovBookstoreDb.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:67902115-088f-4408-907b-f0fd4ed7a14d
    Error Number:5123,State:1,Class:16
    CREATE FILE encountered operating system error 5(Отказано в доступе.) while attempting to open or create the physical file 'C:\Users\Ivan IvanovBookstoreDb.mdf'.
    CREATE DATABASE failed. Some file names listed could not be created. Check related errors.

    Пробовал выдавать права на диск С, запускать через командную строку под Администратором, обновлять SDK и Runtime, менять версии пакетов. Пробовал сменить расположение данных localdb - тоже отказ в доступе. Как решить эту проблему? 

    3 октября 2018 г. 16:32

Ответы

  • Решения из интернета не помогали, пока не нашёл Cumulative Update 6 для SQL Server 2017 Express. Установил, перезагрузился, и всё заработало.
    • Помечено в качестве ответа Энтомолог 4 октября 2018 г. 5:42
    4 октября 2018 г. 5:42