C
- using System;
- using System.IO;
- using GTANetworkAPI;
- using Microsoft.EntityFrameworkCore;
- namespace Server.Model
- {
- public class DefaultDbContext : DbContext
- {
- public static string EnvPath;
- protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
- {
- NAPI.Util.ConsoleOutput("1");
- if (Directory.Exists($"{Main.CurrDirectory}resources"))
- {
- EnvPath =
- $"{Main.CurrDirectory}resources{Path.DirectorySeparatorChar}script{Path.DirectorySeparatorChar}.env";
- }
- else
- {
- EnvPath =
- $"{Main.CurrDirectory}.env";
- }
- if (!File.Exists(EnvPath))
- {
- NAPI.Util.ConsoleOutput("Es existiert keine .env Datei.. erstelle eine neue..");
- using var sw = File.CreateText(EnvPath);
- sw.WriteLine("DATABASE_HOST=");
- sw.WriteLine("DATABASE_USER=");
- sw.WriteLine("DATABASE_PASSWORD=");
- sw.WriteLine("DATABASE_DATABASE=");
- NAPI.Util.ConsoleOutput(".env Datei erstellt.. bitte trage die Datenbankdaten ein");
- return;
- }
- DotNetEnv.Env.Load(EnvPath);
- optionsBuilder.UseMySql($"Server={DotNetEnv.Env.GetString("DATABASE_HOST", "127.0.0.1")};Database={DotNetEnv.Env.GetString("DATABASE_DATABASE", "script")};Uid={DotNetEnv.Env.GetString("DATABASE_USER", "script")};Pwd={DotNetEnv.Env.GetString("DATABASE_PASSWORD", "")}");
- optionsBuilder.EnableSensitiveDataLogging();
- }
- }
- }
Guten Abend, habe folgendes Problem das keine Datenbank verbindung hergestellt wird geschweige der Consolen output erscheint..