Dotnet ef database update не работает

Update-Database fails to login on a LocalDB #7940

Comments

nicolaspierre1990 commented Mar 21, 2017 •

I’m trying to build an app that is based on Code First database Model. So after I added the migrations I tried to update the database with the Update-Database command in the Package Manager of Visual Studio 2017, because the dotnet ef command seems not to work with me from a console. (which I don’t know why aswell) But I’m always getting the error Login failed for user ». Now I searched the internet but I didn’t get any wiser out of it.

Читайте также:  Как ехать если дворники сломались

Steps to reproduce

  • Open Package Manager Console
  • Execute Update-Database Command
  • Error

Further technical details

EF Core version: 1.1.1.
Database Provider: Microsoft.EntityFrameworkCore.SqlServer
Operating system: Windows 10 Enterprise N
IDE:

The text was updated successfully, but these errors were encountered:

smitpatel commented Mar 21, 2017

I tried reproducing this.
Changes required to run EF commands,

  1. Delete global.json from root directory. It is picking up older version of dotnet cli which does not work with new csproj.
  2. In your startup you don’t need line services.AddEntityFrameworkSqlServer().AddDbContext (); . AddDbContext will do all work for you.

PMC commands:
If you are not able to get ef commands in PMC then probably the init script did not run (nuget bug). Restarting VS is one solution. If that does not work then uninstall & reinstall package that will run init script.
Invoke Update-Database from Flexure.Domain project with passing Flexure as startup project, migrations applied successfully.

dotnet ef command line tools:
To use dotnet ef on command line the package you need is Microsoft.EntityFrameworkCore.Tools.Dotnet It is dotnet CLI tool so you need to manually edit csproj file to install it. Adding following code in Flexure.Domain.csproj will give you dotnet ef

This gives you dotnet ef in Flexure.Domain project directory. Invoke `dotnet ef database update» from that directory with passing startup project Flexure updates the database.

At first I got error that log in failed. Though it was because the SQL instance being used in connection string was not available in my machine & I had to change the instance name.

Check your connection string if it is correct. Try ADO.NET provider or visual studio to check if you can actually connect to database.

nicolaspierre1990 commented Mar 22, 2017 •

Trying your solution gives me this.

EDIT:
Verbose output

E:\Nicolas\flexure\flexure-api\src\Flexure.Domain (master)
λ dotnet ef database update —verbose
Using project ‘E:\Nicolas\flexure\flexure-api\src\Flexure.Domain\Flexure.Domain.csproj’.
Using startup project ‘E:\Nicolas\flexure\flexure-api\src\Flexure.Domain\Flexure.Domain.csproj’.
dotnet msbuild /target:GetEFProjectMetadata /property:EFProjectMetadataFile=C:\Users\Nicolas\AppData\Local\Temp\tmpA1B9.tmp /verbosity:quiet /nologo E:\Nicolas\flexure\flexure-api\src\Flexure.Domain\Flexure.Domain.csproj
dotnet msbuild /target:GetEFProjectMetadata /property:EFProjectMetadataFile=C:\Users\Nicolas\AppData\Local\Temp\tmpA38E.tmp /verbosity:quiet /nologo E:\Nicolas\flexure\flexure-api\src\Flexure.Domain\Flexure.Domain.csproj
dotnet build E:\Nicolas\flexure\flexure-api\src\Flexure.Domain\Flexure.Domain.csproj /verbosity:quiet /nologo

Build succeeded.
0 Warning(s)
0 Error(s)

Источник

dotnet ef database update — No executable found matching command «dotnet-ef»

There are many people that have asked this question before on SO. For the last 3 hours I have sequentially tried each solution, and I get the same No executable found matching command «dotnet-ef» each time. I’d like to understand how to run the command and have it actually execute.

But first a little background:

I am learning how to use ASP.Net Core 1.1 MVC and Entity Framework Core. It is a Microsoft tutorial that can be found here.

The completed tutorial can be downloaded from git, as instructed. Performing these steps I open the download project and follow the steps in the readme.md file in the project root folder. It states the following:

After downloading the project, create the database by entering dotnet ef database update at a command-line prompt

Which I attempted. I used visual studio developer command prompt (as admin) and first change directory to the project root, where the appsettings.json and *.csproj file are located. I then typed in the following:

C:\Users\username\Downloads\Docs-master\aspnetcore\data\ef-mvc\intro\samples\cu-final>dotnet ef database update

No executable found matching command «dotnet-ef»

According to the tutorial, this should «work» as-is.

What is strange to me is that if I run the following command I get output, which indicates to me that dotnet.exe is working.

I am using Windows 10 and Visual Studio 2017 CE Version 15.2. I have both the ASP.NET and web development and .Net Core cross-platform development workloads installed.

I am also using .Net Framework Version 4.6.01586.

Источник

dotnet ef database update build failed #26

Comments

cedriclange commented Apr 28, 2019

Environment data

dotnet —info output:
.NET Core SDK (reflecting any global.json):
Version: 2.2.202
Commit: 8a7ff6789d

Runtime Environment:
OS Name: Windows
OS Version: 10.0.17134
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\2.2.202\

Host (useful for support):
Version: 2.2.3
Commit: 6b8ad509b6

.NET Core SDKs installed:
1.0.0-preview2-1-003177 [C:\Program Files\dotnet\sdk]
1.0.0-rc4-004771 [C:\Program Files\dotnet\sdk]
1.0.0 [C:\Program Files\dotnet\sdk]
1.0.4 [C:\Program Files\dotnet\sdk]
1.1.0 [C:\Program Files\dotnet\sdk]
2.0.0-preview1-005977 [C:\Program Files\dotnet\sdk]
2.0.0 [C:\Program Files\dotnet\sdk]
2.0.2 [C:\Program Files\dotnet\sdk]
2.1.202 [C:\Program Files\dotnet\sdk]
2.1.302 [C:\Program Files\dotnet\sdk]
2.1.401 [C:\Program Files\dotnet\sdk]
2.1.602 [C:\Program Files\dotnet\sdk]
2.2.202 [C:\Program Files\dotnet\sdk]

.NET Core runtimes installed:
Microsoft.AspNetCore.All 2.1.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.2.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.2.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 1.0.3 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 1.0.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 1.0.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 1.1.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 1.1.1 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 1.1.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.0.0-preview1-002111-00 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.0.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.3-servicing-26724-03 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.2.3 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]

Steps to reproduce

after cloning the project, installing the bundle with npm successfully, the probleme comes when am supposed to create the database in the WebApplication project running the command «dotnet ef database update» the build failed

Expected behavior

the migration supposed to work according to the Docs

Источник

Unable to start project — «dotnet ef database update» does not work #40048

Comments

richjhart commented Oct 3, 2019 — with docs.microsoft.com

When I ran the command in Git Bash, I got the following error:

$ dotnet ef database update
Could not execute because the specified command or file was not found.
Possible reasons for this include:

  • You misspelled a built-in dotnet command.
  • You intended to execute a .NET Core program, but dotnet-ef does not exist.
  • You intended to run a global tool, but a dotnet-prefixed executable with this name could not be found on the PATH.

Therefore I can’t run the project and do any more of the tutorial

Document Details

Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

  • ID: 00961883-36eb-f736-b906-73d4c35e69b0
  • Version Independent ID: 3a2fd493-9682-eedf-fad1-571b9391cd46
  • Content: ASP.NET Core with SQL Database — Azure App Service
  • Content Source: articles/app-service/app-service-web-tutorial-dotnetcore-sqldb.md
  • Service: app-service-web
  • GitHub Login: @cephalin
  • Microsoft Alias: cephalin

The text was updated successfully, but these errors were encountered:

BryanTrach-MSFT commented Oct 3, 2019

@richjhart Thanks for the feedback! We are currently investigating and will update you shortly.

sandarvanlaan commented Oct 4, 2019 — with docs.microsoft.com

Similar issue. When I updated the dotnet ef tool using the instructions referenced here (dotnet/efcore#15448 (comment)) by using the command dotnet tool install -g dotnet-ef —version 3.0.0-preview4.19216.3. the new error I receive is:
«dotnet ef database update
System.MissingMethodException: Method not found: ‘System.Text.Json.JsonDocument System.Text.Json.JsonDocument.Parse(System.IO.Stream, System.Text.Json.JsonReaderOptions)’.
at Microsoft.EntityFrameworkCore.Tools.RootCommand.Execute()
at Microsoft.EntityFrameworkCore.Tools.Commands.CommandBase.<>c__DisplayClass0_0.b__0()
at Microsoft.DotNet.Cli.CommandLine.CommandLineApplication.Execute(String[] args)
at Microsoft.EntityFrameworkCore.Tools.Program.Main(String[] args)
Method not found: ‘System.Text.Json.JsonDocument System.Text.Json.JsonDocument.Parse(System.IO.Stream, System.Text.Json.JsonReaderOptions)’.»

Any help would be appreciated. Thanks!

BryanTrach-MSFT commented Oct 5, 2019

If you didn’t and you’re just doing the tutorial, you don’t need bash, just open the command prompt instead.

roalexan commented Oct 6, 2019 — with docs.microsoft.com

I’m getting the same error. I’m on a Windows machine and running:

Install .NET Core
browse: https://dotnet.microsoft.com/learn/dotnet/hello-world-tutorial/intro
click: Download and install
click: Download .NET SDK (64-bit) (installs Microsoft .NET Core SDK 3.0.100)
open Command Prompt
cd c:\p\repos (my working directory)
git clone https://github.com/azure-samples/dotnetcore-sqldb-tutorial
cd dotnetcore-sqldb-tutorial
dotnet restore
dotnet ef database update (get error on this line!)

roalexan commented Oct 6, 2019 — with docs.microsoft.com •

sandarvanlaan commented Oct 6, 2019

@BryanTrach-MSFT — Yes I did run the installer at the URL you referenced. And I’m just in a cmd prompt window. The first command «dotnet restore» works fine, but the second «»dotnet ef database update» still errors out as if the cmd isn’t recognized. I tried @roalexan’s recommended solution, but still getting this:
«Could not execute because the specified command or file was not found.
Possible reasons for this include:

  • You misspelled a built-in dotnet command.
  • You intended to execute a .NET Core program, but dotnet-ef does not exist.
  • You intended to run a global tool, but a dotnet-prefixed executable with this name could not be found on the PATH.»

sandarvanlaan commented Oct 6, 2019

Wow. Ok, I got it. Not sure how much help it’ll be for anyone else. But I ran the full install of Visual Studio 2019. Running the command then gave me this error:
dotnet ef database update
It was not possible to find any compatible framework version
The specified framework ‘Microsoft.AspNetCore.App’, version ‘2.2.0’ was not found.

  • The following frameworks were found:
    2.1.13 at [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
    3.0.0 at [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]

You can resolve the problem by installing the specified framework and/or SDK.

The .NET Core frameworks can be found at:

Aaaaand it finally worked! Alright, thanks all.

dmioks commented Oct 8, 2019

I still have the same problem

My Env:
Win10
MSVS 2019 Community 16.3.1
with
.NET Core 2.1. LTS RUntime
.NET Core 2.2 Runtime
.NET Core 3.0 SDK

I have installed
dotnet tool install -g dotnet-ef —version 3.0.0-preview4.19216.3
(with all variations described by roalexan according https://stackoverflow.com/questions/55974734/ef-core-tools-not-working-on-dotnet-core-3-preview-4)

But still have this stopper
System.MissingMethodException: Method not found: ‘System.Text.Json.JsonDocument System.Text.Json.JsonDocument.Parse(System.IO.Stream, System.Text.Json.JsonReaderOptions)’.
at Microsoft.EntityFrameworkCore.Tools.RootCommand.Execute()
at Microsoft.EntityFrameworkCore.Tools.Commands.CommandBase.<>c__DisplayClass0_0.b__0()
at Microsoft.DotNet.Cli.CommandLine.CommandLineApplication.Execute(String[] args)
at Microsoft.EntityFrameworkCore.Tools.Program.Main(String[] args)
Method not found: ‘System.Text.Json.JsonDocument System.Text.Json.JsonDocument.Parse(System.IO.Stream, System.Text.Json.JsonReaderOptions)’.

It appears either I run command line or bash
(if using bash I have «dotnet: command not found»)

I can temporarily overcome this by uninstalling .NET Core 3.0 SDK (Using MSVS Installer UI -> modify -> Individual components) but it is not appropriate solution for me because this case MSVS uninstalls some important tools for .NET Core developing and I need install them again and it brings me back to have .NET Core 3.0 that again reproduces the issue.

RyanHill-MSFT commented Oct 9, 2019 •

@dmikos .NET Core 3.0 is now GA. Have you tried re-installing the SDK from the Visual Studio Installer? dotnet-ef is available by default.

kstudnik commented Oct 10, 2019 •

I today I had the same issue with dotnet ef database update error.
I reinstalled .NET Core packages as suggested by @RyanHill-MSFT
But unfortunately it ended with the same error as @dmioks
System.MissingMethodException: Method not found: ‘System.Text.Json.JsonDocument System.Text.Json.JsonDocument.Parse(System.IO.Stream, System.Text.Json.JsonReaderOptions)’. at Microsoft.EntityFrameworkCore.Tools.RootCommand.Execute() at Microsoft.EntityFrameworkCore.Tools.Commands.CommandBase.<>c__DisplayClass0_0. b__0() at Microsoft.DotNet.Cli.CommandLine.CommandLineApplication.Execute(String[] args) at Microsoft.EntityFrameworkCore.Tools.Program.Main(String[] args) Method not found: ‘System.Text.Json.JsonDocument System.Text.Json.JsonDocument.Parse(System.IO.Stream, System.Text.Json.JsonReaderOptions)’.

edit:
What helped in my case, was manual install of specific dotnet-ef version
dotnet tool update —global dotnet-ef —version 3.0.0-preview7.19362.6
as mentioned in this case in Stack

BryanTrach-MSFT commented Oct 10, 2019

@kstudnik Yes, this is the workaround that we were going to share as we believe it should help to resolve a majority of the issues on this thread.

Since a majority of these items seem to be troubleshooting related caused by the switch to .net core 3.0 and not by this doc specifically and we believe kstudnik’s response should help, we will now proceed to close this thread. If there are further questions regarding this matter, please tag me in your reply. We will gladly continue the discussion and we will reopen the issue.

Источник

Оцените статью