[Feature] Implementazione completa supporto ODBC

- Aggiunta persistenza campi ODBC (OdbcDsnName, OdbcMode) in CredentialEntity
- Creata migration EF Core per nuovi campi database
- Aggiornato mapping credenziali per caricare/salvare dati ODBC
- Creato OdbcDatabaseManager dedicato (bypass EF Core che non supporta ODBC)
- Aggiornato DataConnectionFactory per usare OdbcDatabaseManager con connessioni ODBC
- Fix auto-load DSN: sostituito @onchange con @bind-Value:after in dropdown tipo database
- Fix test connessione SAP HANA: rimossa query SELECT 1 che causava errori sintassi
- Implementati tutti i metodi IDatabaseManager in OdbcDatabaseManager
- Supporto completo per discovery schema, tabelle e query ODBC

Risolve problema DbContext non configurato per ODBC e abilita connessioni ODBC complete.
This commit is contained in:
Alessio Dal Santo
2026-02-02 18:24:44 +01:00
parent e7fb9a5cc7
commit 01f78466df
22 changed files with 3615 additions and 49 deletions
@@ -21,6 +21,7 @@ public static class CredentialExtensions
CredentialManager.Models.DatabaseType.Sqlite => DataConnection.Enums.DatabaseType.Sqlite,
CredentialManager.Models.DatabaseType.DB2 => DataConnection.Enums.DatabaseType.DB2,
CredentialManager.Models.DatabaseType.SapHana => DataConnection.Enums.DatabaseType.SapHana,
CredentialManager.Models.DatabaseType.Odbc => DataConnection.Enums.DatabaseType.Odbc,
_ => throw new NotSupportedException($"Database type {credentialDbType} not supported")
};
}
@@ -39,6 +40,7 @@ public static class CredentialExtensions
DataConnection.Enums.DatabaseType.Sqlite => CredentialManager.Models.DatabaseType.Sqlite,
DataConnection.Enums.DatabaseType.DB2 => CredentialManager.Models.DatabaseType.DB2,
DataConnection.Enums.DatabaseType.SapHana => CredentialManager.Models.DatabaseType.SapHana,
DataConnection.Enums.DatabaseType.Odbc => CredentialManager.Models.DatabaseType.Odbc,
_ => throw new NotSupportedException($"Database type {dataConnectionDbType} not supported")
};
}
@@ -250,6 +250,7 @@ public class DataConnectionCredentialService : IDataConnectionCredentialService
CredentialManager.Models.DatabaseType.PostgreSql => await TestPostgreSqlConnection(connectionString, credential),
CredentialManager.Models.DatabaseType.Oracle => await TestOracleConnection(connectionString, credential),
CredentialManager.Models.DatabaseType.Sqlite => await TestSqliteConnection(connectionString, credential),
CredentialManager.Models.DatabaseType.Odbc => await TestOdbcConnection(connectionString, credential),
_ => (false, $"Test di connessione non implementato per {credential.DatabaseType}")
};
}
@@ -344,6 +345,65 @@ public class DataConnectionCredentialService : IDataConnectionCredentialService
return (false, $"Errore SQLite: {ex.Message}");
}
}
private async Task<(bool Success, string Message)> TestOdbcConnection(string connectionString, DatabaseCredential credential)
{
try
{
using var connection = new System.Data.Odbc.OdbcConnection(connectionString);
await connection.OpenAsync();
// Non eseguiamo query di test perché alcuni database (come SAP HANA)
// hanno sintassi specifiche e potrebbero fallire anche con SELECT 1
// Ci limitiamo a testare l'apertura della connessione
var details = new System.Text.StringBuilder();
details.AppendLine("Connessione ODBC riuscita!");
details.AppendLine();
details.AppendLine("Dettagli:");
if (credential.OdbcMode == CredentialManager.Models.OdbcConnectionMode.Dsn && !string.IsNullOrEmpty(credential.OdbcDsnName))
{
details.AppendLine($"- DSN: {credential.OdbcDsnName}");
details.AppendLine($"- Tipo: {(credential.OdbcMode == CredentialManager.Models.OdbcConnectionMode.Dsn ? "DSN" : "Custom")}");
}
else
{
details.AppendLine($"- Modalità: Custom Connection String");
if (!string.IsNullOrEmpty(credential.Host))
details.AppendLine($"- Server: {credential.Host}" + (credential.Port > 0 ? $":{credential.Port}" : ""));
if (!string.IsNullOrEmpty(credential.DatabaseName))
details.AppendLine($"- Database: {credential.DatabaseName}");
}
details.AppendLine($"- Driver: {connection.Driver}");
details.AppendLine($"- Server Version: {connection.ServerVersion}");
details.AppendLine($"- Database: {connection.Database}");
details.AppendLine($"- Timeout: {credential.CommandTimeout}s");
return (true, details.ToString());
}
catch (System.Data.Odbc.OdbcException odbcEx)
{
var errorDetails = new System.Text.StringBuilder();
errorDetails.AppendLine($"Errore ODBC: {odbcEx.Message}");
errorDetails.AppendLine();
errorDetails.AppendLine("Dettagli errori:");
foreach (System.Data.Odbc.OdbcError error in odbcEx.Errors)
{
errorDetails.AppendLine($"- [{error.SQLState}] {error.Message}");
errorDetails.AppendLine($" Source: {error.Source}");
}
return (false, errorDetails.ToString());
}
catch (Exception ex)
{
return (false, $"Errore ODBC: {ex.Message}");
}
}
public async Task<(bool Success, string Message)> TestRestApiConnectionAsync(string credentialName)
{
try