Add SSL, MDC database, and custom HANA connection parameters
Fixes 'error while parsing protocol' HanaException by supporting SSL/TLS encryption, Multi-Tenant Database Container (MDC) database name, and arbitrary additional connection parameters. - HanaServer model: added DatabaseName, UseSsl, ValidateCertificate, AdditionalParams fields + BuildConnectionString() helper - HanaQueryService: accepts HanaServer directly, uses BuildConnectionString() for full parameter support - AppDbContext: added EnsureSchema() method that uses PRAGMA table_info + ALTER TABLE ADD COLUMN to add the new fields to existing SQLite databases without losing data (EnsureCreated does not update schema) - Program.cs: calls EnsureSchema on startup before seeding - Standorte.razor: server dialog now exposes DatabaseName, UseSsl, ValidateCertificate, AdditionalParams with helper texts; test connection uses new signature https://claude.ai/code/session_012heAXNMbbyxqYf2S2HrKLj
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
using System.Data;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using TrafagSalesExporter.Models;
|
||||
|
||||
@@ -13,6 +14,46 @@ public class AppDbContext : DbContext
|
||||
public DbSet<ExportSettings> ExportSettings => Set<ExportSettings>();
|
||||
public DbSet<ExportLog> ExportLogs => Set<ExportLog>();
|
||||
|
||||
/// <summary>
|
||||
/// Fügt Spalten zu existierenden Tabellen hinzu, die bei neueren Versionen
|
||||
/// hinzugekommen sind. EnsureCreated aktualisiert das Schema nicht automatisch.
|
||||
/// </summary>
|
||||
public static void EnsureSchema(AppDbContext db)
|
||||
{
|
||||
AddColumnIfMissing(db, "HanaServers", "DatabaseName", "TEXT NOT NULL DEFAULT ''");
|
||||
AddColumnIfMissing(db, "HanaServers", "UseSsl", "INTEGER NOT NULL DEFAULT 0");
|
||||
AddColumnIfMissing(db, "HanaServers", "ValidateCertificate", "INTEGER NOT NULL DEFAULT 0");
|
||||
AddColumnIfMissing(db, "HanaServers", "AdditionalParams", "TEXT NOT NULL DEFAULT ''");
|
||||
}
|
||||
|
||||
private static void AddColumnIfMissing(AppDbContext db, string table, string column, string type)
|
||||
{
|
||||
var conn = db.Database.GetDbConnection();
|
||||
if (conn.State != ConnectionState.Open) conn.Open();
|
||||
|
||||
bool exists = false;
|
||||
using (var cmd = conn.CreateCommand())
|
||||
{
|
||||
cmd.CommandText = $"PRAGMA table_info({table})";
|
||||
using var reader = cmd.ExecuteReader();
|
||||
while (reader.Read())
|
||||
{
|
||||
if (string.Equals(reader["name"]?.ToString(), column, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
exists = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!exists)
|
||||
{
|
||||
using var alter = conn.CreateCommand();
|
||||
alter.CommandText = $"ALTER TABLE {table} ADD COLUMN {column} {type}";
|
||||
alter.ExecuteNonQuery();
|
||||
}
|
||||
}
|
||||
|
||||
public static void SeedIfEmpty(AppDbContext db)
|
||||
{
|
||||
if (db.HanaServers.Any()) return;
|
||||
|
||||
Reference in New Issue
Block a user