Files
DP44/docs/ai/DataPRO/Modules/InstallerCustomActions/DBConfiguration.md
2026-04-17 14:55:32 -04:00

145 lines
7.7 KiB
Markdown

---
source_files:
- DataPRO/Modules/InstallerCustomActions/DBConfiguration/MigrationStatus.cs
- DataPRO/Modules/InstallerCustomActions/DBConfiguration/DBConfig.cs
- DataPRO/Modules/InstallerCustomActions/DBConfiguration/CommonUtilities.cs
- DataPRO/Modules/InstallerCustomActions/DBConfiguration/DBTypeChoice.Designer.cs
generated_at: "2026-04-17T15:53:09.999426+00:00"
model: "zai-org/GLM-5-FP8"
schema_version: 1
sha256: "759c4bea5bfc5343"
---
# DBConfiguration Module Documentation
## 1. Purpose
The DBConfiguration module is a Windows Forms application that serves as a custom action for the DataPRO installer. It provides database configuration and migration capabilities, allowing users to choose between Local, Centralized, or Both database configurations. The module handles SQL Server Express LocalDB instance management (create, start, stop, delete), database attach/detach operations for DataPRO and ISO databases, and supports initializing databases to preset configurations (TSR AIR, Aero, Crash) or migrating data from previous installations.
## 2. Public Interface
### MigrationStatus Class
```csharp
public class MigrationStatus
```
A data class representing migration status information.
**Properties:**
- `StatusTypes StatusType { get; set; }` - The type of status being reported
- `string StatusText { get; set; }` - The status message text
**Nested Enum:**
```csharp
public enum StatusTypes
{
Status,
MigrationStatus,
SourceDb
}
```
---
### DBConfig Class (Static)
```csharp
static class DBConfig
```
The application entry point class.
**Methods:**
- `static void Main(string[] args)` - Entry point that parses command-line arguments and launches either the configuration UI or TSR AIR initialization. Accepts arguments in order: `targetDir`, `productVersion`, `noUI`, `tsrAirGo` (boolean). Supports standalone mode with 0 or 2 arguments.
---
### CommonUtilities Class
```csharp
public class CommonUtilities
```
Core utility class for database operations.
**Constructor:**
- `CommonUtilities()` - Initializes the event log with source "DataPRODbMigratorInstaller"
**Public Methods:**
- `void InitializeDbToTSRAIR(string targetDir)` - Initializes the database to TSR AIR settings. Attaches databases, initializes via `DbOperations.Connection.Initialize()`, then detaches.
- `string Attach(string targetDbDir, string scriptsDir)` - Attaches the previous LocalDB database. Logs and sets migration status before calling `InstallDatabase()`.
- `string InstallDatabase(string dBdir, string dbName, string scriptsDir)` - Creates, starts a new LocalDB instance, and attaches both DataPRO and ISO databases. Sets `DbOperations._usingCentralizedDB = false`, `DbOperations._usingMSSQL = true`, and `DbOperations._usingNTLMAuthentication = true`.
- `string Detach(string sourceDbName, string targetDbDir, string scriptsDir)` - Detaches both the specified source database and ISO database.
- `MigrationStatus SetMigrationStatus(string migrationStatus, bool output = false)` - Sets the current migration status text and returns a `MigrationStatus` instance with `StatusTypes.MigrationStatus`.
- `string ProcessSqlLocalDbCommand(string command)` - Executes a SQL LocalDB command using the highest version of SQL Server Express LocalDB installed.
- `static string AttachOrDetachDatabase(string scriptsDir, string dbName, string sqlDbFileName, string sqlLogFileName, string attachOrDetach)` - Executes a batch file to attach or detach a database using sqlcmd.exe.
- `static void OutputHandler(object sendingProcess, DataReceivedEventArgs outLine)` - Event handler for process output, appends to static `sb` StringBuilder.
- `static string SqlCommandProcessor(string sqlLocalDbExeFileName, string command)` - Executes a SQL LocalDB command and returns output/errors.
- `static string BatchCommandProcessor(string batchFileName, string dbName, string sqlDbFileName, string sqlLogFileName, string fullSqlcmdPath)` - Executes a batch file with database parameters and returns output/errors.
**Public Fields:**
- `public static StringBuilder sb` - Static StringBuilder shared across process output handling
---
### DBTypeChoice Class (Windows Form)
```csharp
partial class DBTypeChoice
```
Configuration UI form for selecting database type and initialization options.
**Key UI Controls:**
- `rbLocal`, `rbCentralized`, `rbBoth` - Radio buttons for database type selection
- `rbMigrateLocal`, `rbAero`, `rbCrash`, `rbTSRAIR`, `rbNoneOfTheAbove` - Radio buttons for initialization mode
- `tbDBHostname`, `tbDBName`, `tbDBUser`, `tbDBPassword` - Text fields for centralized database connection
- `cbUseNTLMAuthentication`, `cbShowPassword`, `cbCopyConfig` - Checkbox options
- `tbSourceDB`, `tbDestinationDB` - Text fields for migration paths (conditionally visible)
- `btnOK`, `btnCancel` - Action buttons
## 3. Invariants
- **SQL Server Express LocalDB 2014** is a prerequisite and must be installed unless subsequently uninstalled
- Database name is hardcoded to `"DataPRO"` during TSR AIR Go installation and cannot be changed
- `Settings.Default.LocalDbFolder`, `Settings.Default.ScriptsFolder`, and other Settings values must be properly configured
- The registry path `SOFTWARE\Microsoft\Microsoft SQL Server\LocalDB\InstalledVersions` must exist for LocalDB detection
- Process output handling uses a shared static `StringBuilder` that is cleared before each operation
- The form is displayed as topmost (`TopMost = true`) with no control box (`ControlBox = false`)
## 4. Dependencies
**External Dependencies (from imports):**
- `DTS.Common.Storage` - Provides `ConfigInitializationHelper`
- `DTS.Common.Enums` - Provides `InitializationTypes`
- `DTS.Common.Utilities` - Referenced in namespace
- `DTS.Common.Utils.Database` - Provides `GetODBCToolsPath()`
- `Microsoft.Win32` - Registry access
- `System.Windows.Forms` - UI framework
- `System.Diagnostics` - `EventLog`, `Process` classes
- `System.Runtime.InteropServices` - P/Invoke support
**Internal Dependencies:**
- `DbOperations.Connection` - Used for database connection settings (`DBName`, `Server`, `Initialize()`)
- `DbOperations` - Static fields: `_usingCentralizedDB`, `_usingMSSQL`, `_usingNTLMAuthentication`
- `Settings.Default` - Application settings for paths, instance names, messages
**Native Dependencies:**
- `kernel32.dll` - `GetConsoleWindow()` function
- `user32.dll` - `ShowWindow()` function
## 5. Gotchas
1. **DEBUG mode hardcodes**: When compiled with DEBUG defined, the application uses hardcoded test paths (`D:\DTS\DTS.Suite\4.4.309\DataPRO`) and version strings. The comment instructs developers to enable this via project properties.
2. **Console window visibility**: The application hides/shows the console window via P/Invoke. In standalone mode (0 args), the window briefly flashes; with 2 args, it remains visible; when called from installer (4 args), it's hidden.
3. **Shared static StringBuilder**: The `sb` field is static and shared across `SqlCommandProcessor` and `BatchCommandProcessor`. It's cleared at the start of each call, which could cause issues if multiple operations run concurrently.
4. **Argument parsing fragility**: The `Main` method parses arguments by position (index 0-3) rather than named parameters, making the calling convention brittle.
5. **Registry dependency**: `GetSqlServerLocalDBPath()` returns `string.Empty` if the LocalDB registry keys are not found, which causes `ProcessSqlLocalDbCommand` to return an error message but not throw an exception.
6. **UI element visibility**: Several controls (`lblSourceDB`, `tbSourceDB`, `btnBrowseSourceDB`, `lblDestinationDB`, `tbDestinationDB`, `btnBrowseDestinationDB`) are initialized with `Visible = false` and their visibility logic is not shown in the designer file (likely controlled in the code-behind file `DBTypeChoice.cs` which was not provided).