Tiltyboi
Tiltyboi
CC#
Created by Tiltyboi on 8/10/2024 in #help
✅ Cannot connect to mysql docker container db from AspNet Core App
A AspNet Core App using EF-Core cannot connect to local db container running mysql. I have made sure it forwards the correct port (default 3306). ASet my connection string in my app to:
"ConnectionStrings": {
"SqlConnection": "Server=172.17.0.2;Database=test-db;User Id=root;Password=my-secret-pw;"
}
"ConnectionStrings": {
"SqlConnection": "Server=172.17.0.2;Database=test-db;User Id=root;Password=my-secret-pw;"
}
So why doesnt it work? I alsot ried setting server to localhost and 127.0.0.1 ....
19 replies
CC#
Created by Tiltyboi on 8/10/2024 in #help
EF-Core migrations issue
I have split a large project into multiple places. I have 1 class-library with my classes and contexts, 1 class library where my migrations will go and then my main app. When i do Add-Migration init -Project <lib-with-context> it throws this lovely error:
Unable to create a 'DbContext' of type ''. The exception 'Unable to resolve service for type 'Microsoft.EntityFrameworkCore.DbContextOptions`1[SadBot.Core.Database.RPGContext]' while attempting to activate 'SadBot.Core.Database.RPGContext'.' was thrown while attempting to create an instance. For the different patterns supported at design time, see https://go.microsoft.com/fwlink/?linkid=851728
Unable to create a 'DbContext' of type ''. The exception 'Unable to resolve service for type 'Microsoft.EntityFrameworkCore.DbContextOptions`1[SadBot.Core.Database.RPGContext]' while attempting to activate 'SadBot.Core.Database.RPGContext'.' was thrown while attempting to create an instance. For the different patterns supported at design time, see https://go.microsoft.com/fwlink/?linkid=851728
2 replies
CC#
Created by Tiltyboi on 8/5/2024 in #help
dotnet-ef error creating migrations
Im following a youtube tutorial to create a discord bot and in a part the author connects to a database. (vid for reference: https://www.youtube.com/watch?v=EHmtrqb5VMk&list=PLS6sInD7ThM0Zb8F_KBl4T_jGF1e3apsc&index=11) (P.S excuse my cringe project name) When im calling the command from CMD its like this:
dotnet-ef migrations add InitialCreate -p ../SadBot.Migrations/SadBot.Migrations.csproj --context SadBot.Core.Database.RPGContext --startup-project ./SadMemerBot.csproj
dotnet-ef migrations add InitialCreate -p ../SadBot.Migrations/SadBot.Migrations.csproj --context SadBot.Core.Database.RPGContext --startup-project ./SadMemerBot.csproj
And then i get this error: No DbContext named 'RPGContext' was found. Or with full path No DbContext named 'SadBot.Core.Database.RPGContext' was found. Im following exactly and linking projects together, saving the csproj files and i can import my class in the program.cs so they are linked.. Why creating migrations doesnt work then? My Project strucutre is like so:
SadBot (solution)
-/SadBot.Core
-/Database
-/Entity.cs
-/RPGContext.cs
-/SadBot.Migrations
-/SadMemerBot (Startup proj)
-/Program.cs
SadBot (solution)
-/SadBot.Core
-/Database
-/Entity.cs
-/RPGContext.cs
-/SadBot.Migrations
-/SadMemerBot (Startup proj)
-/Program.cs
3 replies
CC#
Created by Tiltyboi on 11/27/2023 in #help
C# IConfiguration not loading appsettings
Anyone knows why my appsettings isnt found? It exists in the same project in my solution as i run? Its a simple console application with my appsettings.json in it but its not found?
var builder = new ConfigurationBuilder()
.AddJsonFile("appsettings.json", true, true)
//.AddUserSecrets<Program>()
.AddEnvironmentVariables();
_config = builder.Build();
var builder = new ConfigurationBuilder()
.AddJsonFile("appsettings.json", true, true)
//.AddUserSecrets<Program>()
.AddEnvironmentVariables();
_config = builder.Build();
But when i user User Secrets it works fine.
178 replies