c#
private static void CreateGenericDatabase(DataBaseConfig dbBaseConfig)
{
try
{
string connectionString = DatabaseConnectionGen.GetConnectionString(dbBaseConfig.SqlServerIp, dbBaseConfig.SqlType, dbBaseConfig.Username, dbBaseConfig.Password, dbBaseConfig.WindowsAuth, "CoreDb");
using TestDbContext dbContext = DatabaseConnectionGen.GenerateBuilder(dbBaseConfig.SqlType, connectionString);
dbContext.Database.EnsureCreated();
using IDbContextTransaction transaction = dbContext.Database.BeginTransaction();
dbContext.Database.Migrate();
transaction.Commit();
}
catch(SqlException ex)
{
// Detaillierte Protokollierung der SqlException
Debug.WriteLine("SQL Exception:");
Debug.WriteLine($"Message: {ex.Message}");
Debug.WriteLine($"Error Code: {ex.ErrorCode}");
Debug.WriteLine($"Stack Trace: {ex.StackTrace}");
if (ex.InnerException != null)
{
Debug.WriteLine($"Inner Exception: {ex.InnerException.Message}");
}
throw;
}
catch (Exception ex)
{
// Detaillierte Protokollierung anderer Ausnahmen
Debug.WriteLine("Exception:");
Debug.WriteLine($"Message: {ex.Message}");
Debug.WriteLine($"Stack Trace: {ex.StackTrace}");
if (ex.InnerException != null)
{
Debug.WriteLine($"Inner Exception: {ex.InnerException.Message}");
}
throw; // Re-throw the exception to propagate it further
}
}