Skip to main content

200 posts tagged with "Errors"

Common Errors and Troubleshooting in Programming

View All Tags

Fixed: "ERROR 1227 (42000): Access denied; you need (at least one of) the SUPER or SYSTEM_VARIABLES_ADMIN privilege(s)" in MySQL

· 5 min read
Jagdish Kumawat
Founder @ Dewiride

Changing a MySQL setting failed with ERROR 1227 (42000): Access denied; you need (at least one of) the SUPER or SYSTEM_VARIABLES_ADMIN privilege(s) for this operation. The word GLOBAL in the statement is the cause. Most of the time you don't want the whole server changed anyway, and one word fixes it.

Fixed: "ERROR 1227 (42000): Access denied; you need (at least one of) the PROCESS privilege(s) for this operation" in MySQL

· 5 min read
Jagdish Kumawat
Founder @ Dewiride

I wanted to see which transactions were open, and MySQL said ERROR 1227 (42000): Access denied; you need (at least one of) the PROCESS privilege(s) for this operation. The account has full rights on its own database, and that's not enough. Here's why, and the right way to fix it without making your application's account more powerful.

Fixed: "ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transaction" in MySQL

· 6 min read
Jagdish Kumawat
Founder @ Dewiride

An UPDATE hung for a while, then failed with ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transaction. Raising the timeout is the tempting fix, and the wrong one, because the real problem is another transaction holding the row. Here's how to find it, and a surprise about what the error leaves behind.

Fixed: "ERROR 1213 (40001): Deadlock found when trying to get lock; try restarting transaction" in MySQL

· 8 min read
Jagdish Kumawat
Founder @ Dewiride

An ordinary UPDATE failed with ERROR 1213 (40001): Deadlock found when trying to get lock; try restarting transaction, and MySQL threw away everything the transaction had done so far. Two transactions had taken the same rows in opposite orders. Here's how to see that for yourself, and the small change that stops it.

Fixed: "Body was inferred but the method does not allow inferred body parameters" in a Minimal API

· 6 min read
Jagdish Kumawat
Founder @ Dewiride

After I added one small GET endpoint, every request to my minimal API answered 500, health checks included. The log said Body was inferred but the method does not allow inferred body parameters. The endpoint took a record as a parameter, and ASP.NET Core assumes that comes from the JSON body, which GET doesn't get. [AsParameters] tells it to read the query string instead.

Fixed: "Cannot resolve scoped service 'InventoryDbContext' from root provider" in ASP.NET Core

· 5 min read
Jagdish Kumawat
Founder @ Dewiride

I wanted to read something from the database once, while the app started, so I asked app.Services for the DbContext in Program.cs. The app crashed: Cannot resolve scoped service 'Dewiride.Inventory.Data.InventoryDbContext' from root provider. Scoped services need a scope, and at startup there's no request to provide one. You can create one yourself in two lines.

Fixed: "Cannot consume scoped service 'DbContextOptions' from singleton" in ASP.NET Core

· 6 min read
Jagdish Kumawat
Founder @ Dewiride

My API refused to start: Cannot consume scoped service 'Microsoft.EntityFrameworkCore.DbContextOptions1[…InventoryDbContext]' from singleton 'Dewiride.Inventory.Api.CategoryCache'.A small cache class, registered as a singleton, asked for theDbContext. A singleton lives as long as the app, and a DbContextbelongs to one request, so ASP.NET Core stops it.IServiceScopeFactory` is the way for a singleton to use one.

Fixed: "415 Unsupported Media Type" from a POST to an ASP.NET Core Minimal API

· 5 min read
Jagdish Kumawat
Founder @ Dewiride

A POST with perfectly good JSON came back as 415 Unsupported Media Type, and the API's log had nothing to say about it. The JSON wasn't the problem: the request never said it was JSON. curl labels a -d body as a web form unless you tell it otherwise, and a minimal API endpoint that expects JSON won't touch that.