Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When executing the command "Scaffold-DbContext" I get the error "ScriptHalted"

I am trying to compute the entity framework tutorial" Creating a Model for an Existing Database in Entity Framework Core // entityframeworktutorial.net"-  

When I enter the command: PM> Scaffold-DbContext" Server =. \ SQLEXPRESS1; Database = SCHOOLDB.MDF; Trusted_Connection = True; " Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models  
I get the error: ScriptHalted enter image description here 

Database Picture
enter image description here

Used by:
   - Visual Studio - 2019. Community - 16.3.6;
   - Console application. Core 3.0;
   - Microsoft.EntityFrameworkCore - 3.0.0;
   - Microsoft.EntityFrameworkCore.Tools - 3.0.0;
  Story:
  - I installed "Microsoft.EntityFrameworkCore - 3.0.0;"
  - I run the command: PM> Scaffold-DbContext" Server =. \ SQLEXPRESS1; Database = SCHOOLDB.MDF; Trusted_Connection = True; " Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models

  - I get an error: The name" Scaffold-DbContext "is not recognized as the name of the cmdlet, function, script file, or executable program. Check for correctness. spelling of the name, as well as the presence and correctness of the path, then try again. line: 1 character: 19 + Scaffold-DbContext <<<< "Server =. \ SQLEXPRESS1; Database = SCHOOLDB.MDF; Trusted_Connection = True;" Microsoft.EntityFrameworkCore.SqlSe rver -OutputDir Models     + CategoryInfo: ObjectNotFound: (Scaffold-DbContext: String) [], CommandNotFoundException     + FullyQualifiedErrorId: CommandNotFoundException

  - I installed Microsoft.EntityFrameworkCore.Tools (according to the recommendation -"Scaffold-DbContext 'is not recognized -> require EF Tools // github.com")`

  - I run the command: PM> Scaffold-DbContext" Server =. \ SQLEXPRESS1; Database = SCHOOLDB.MDF; Trusted_Connection = True; " Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models
  - I get an error: ScriptHalted
  Question.
How to fix the "ScriptHalted" error?

like image 435
eusataf Avatar asked Sep 21 '25 01:09

eusataf


2 Answers

I had the same problem today and I am using Windows 7. Windows 7 uses powershell 2.0 so I upgraded it to 5.1, you can upgrade it from here - https://learn.microsoft.com/en-us/powershell/scripting/install/installing-windows-powershell?view=powershell-6

Upgrading this solved my problem. I found this solution from here - https://github.com/aspnet/AspNetCore.Docs/issues/14863

like image 174
Doğa Babacan Avatar answered Sep 22 '25 15:09

Doğa Babacan


Upgrade Powershell to 5.1

This is the link from where you can download according to your system requirement.

https://learn.microsoft.com/en-us/powershell/scripting/install/windows-powershell-system-requirements?view=powershell-7

like image 38
rkpaul Avatar answered Sep 22 '25 13:09

rkpaul