Unable to update database using Entity Core Framework after migrations
I tried updating my database after running migrations but got a System exception error. This is the command I used :
dotnet ef database update
This is the error message :
System.ArgumentException: Connection string keyword 'server' is not supported
Document Details
⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
- ID: 6719f08e-3bd7-dc1a-71df-f2ef9fbca9d8
- Version Independent ID: 7096fdb3-612e-9e00-bd0b-8ea4886a09ce
- Content: Part 2, add a model
- Content Source: aspnetcore/tutorials/razor-pages/model.md
- Product: aspnet-core
- Technology: aspnetcore-tutorials
- GitHub Login: @Rick-Anderson
- Microsoft Alias: riande
What environment? What version? What does the connection string look like.
The tutorial works. I'm not sure what step you missed. You might try asking on StackOverflow,.
I am running the tutorial on Windows 10. This is a snapshot of the connection string : "Server=(localdb)\mssqllocaldb;Database=RazorPagesMovieContext-236d8ba3-1734-471d-a757-143be5b60c2f;Trusted_Connection=True;MultipleActiveResultSets=true"
I will not say the tutorial is not working if everything worked fine. I checked Stackoverflow for answers before creating the issues here. All what it pointed was some error connected to ADO.NET but none linked to the SystemException that was thrown. I will gladly accept any help to fix the issue
Exit/restart VS.
The tutorial is mis-leading up to this point. The development setting is using options.UseSqlite in Startup.cs, but the connection string in appsettings.json is using SqlServer format.
change SqlServer format "Server=(localdb)\mssqllocaldb;Database=RazorPagesMovieContext-236d8ba3-1734-471d-a757-143be5b60c2f;Trusted_Connection=True;MultipleActiveResultSets=true"
To SqlLite format: "ConnectionStrings": { "RazorPagesMovieContext": "Data Source=MvcMovie.db" }
@wadepickett please review
The tutorial is mis-leading up to this point. The development setting is using options.UseSqlite in Startup.cs, but the connection string in appsettings.json is using SqlServer format.
When you scaffold for SQLite, it generates the SQLite connection string.
No idea. Follow the step of the tutorial,
https://docs.microsoft.com/en-us/aspnet/core/tutorials/razor-pages/model?view=aspnetcore-5.0&tabs=visual-studio-code
dotnet-aspnet-codegenerator razorpage -m Movie -dc RazorPagesMovieContext -udl -outDir Pages\Movies --referenceScriptLibraries
Adding this
if (Environment.IsDevelopment())
{
services.AddDbContext
Then run dotnet ef migrations add InitialCreate dotnet ef database update
may duplicate the problem.
Use SQLite for development, SQL Server for production is exactly that, for deploying to production, not for this tutorial.
@wadepickett
dotnet-aspnet-codegenerator razorpage -m Movie -dc RazorPagesMovieContext -udl -outDir Pages/Movies --referenceScriptLibraries
Why are we using -dc RazorPagesMovieContext ? I think that's used when you specify the db context. In this case we want the scaffolder to generate it.
@wadepickett you're also missing
--useSqlite|-sqlite : Flag to specify if DbContext should use SQLite instead of SQL Server.
This is a pri 0 bug.
I know this framework two years ago. But I found no way to learn this framework at that time. Today, I try to learn it again. And I already stucked at part two of the first tutorial due to this problem. Why can the .NET ecosystem have a completable and enlightenment course? Like Laracasts from Laravel ecosystem.
@Rick-Anderson, I am on this one now.
You asked: "Why are we using -dc RazorPagesMovieContext ?"
I don't know actually, sorry. You had -dc RazorPagesMovieContext in your topic for your updates to Model.md from 2018 to 2021.
2018-12 Update model.md (#9947) dotnet aspnet-codegenerator razorpage -m Movie -dc RazorPagesMovieContext -udl -outDir Pages\Movies --referenceScriptLibraries
2020-1 Update model.md by Rick-Anderson · Pull Request #16588 dotnet aspnet-codegenerator razorpage -m Movie -dc RazorPagesMovieContext -udl -outDir Pages\Movies --referenceScriptLibraries
2021-4 Update model.md (#22029) dotnet aspnet-codegenerator razorpage -m Movie -dc RazorPagesMovieContext -udl -outDir Pages/Movies --referenceScriptLibraries -sqlite
2021-5 Update to Model.md 22367 dotnet aspnet-codegenerator changed to dotnet-aspnet-codegenerator and still has -dc RazorPagesMovieContext. dotnet-aspnet-codegenerator razorpage -m Movie -dc RazorPagesMovieContext -udl -outDir Pages/Movies --referenceScriptLibraries -sqlite
-dc or no -dc:
On (#22029) you originally tried the following without -dc, but it didn’t work: dotnet aspnet-codegenerator razorpage -m Movie -udl -outDir Pages/Movies --referenceScriptLibraries -sqlite … so you put the -dc RazorPagesMovieContext back in. That is why it is there.
At the time you asked deepchoudhery for verification but I don't think we got a reply, he may have been out.
I am honestly not sure what the proper command is supposed to be for this case. There is very little info available. It seems like the scaffolding isn't working how we expect it to, I don't know how to get it to generate on its own if the dc is not specified in the command.
If you know exactly what it should be, please let me know. If not, I will check with the developer on the intent vs. how it works now. The command reference may also need to be updated. Thanks for all the help.
Instructions work fine as they are.