9.9 KiB
source_files, generated_at, model, schema_version, sha256
| source_files | generated_at | model | schema_version | sha256 | ||||
|---|---|---|---|---|---|---|---|---|
|
2026-04-16T04:44:09.733583+00:00 | Qwen/Qwen3-Coder-Next-FP8 | 1 | 34f445ff6d14ccf5 |
Documentation: DBConfiguration Module
1. Purpose
This module provides database configuration and initialization logic for the DataPRO application during installation and migration scenarios. It serves as a standalone executable (DBConfiguration.exe) that handles local SQL Server Express LocalDB instance management—including creation, attachment, and detachment of databases (DataPRO and ISO)—and supports multiple initialization modes (e.g., TSR AIR, Crash, Aero, migration from previous local DB). It also exposes a minimal MigrationStatus class for conveying progress during operations. The module is invoked by the installer (via command-line arguments) or standalone (for debugging/testing), and integrates with Windows Forms for interactive configuration when UI is enabled.
2. Public Interface
DBConfiguration.MigrationStatus
StatusTypesenum: Defines three status categories:Status,MigrationStatus, andSourceDb.StatusTypeproperty (StatusTypes): Indicates the type of status being reported.StatusTextproperty (string): Contains the human-readable status message.
DBConfiguration.DBConfig
Main(string[] args): Static entry point. Parses command-line arguments to determine execution mode (installer vs. standalone, UI vs. silent), and dispatches to eitherDBTypeChoiceform (interactive) orCommonUtilities.InitializeDbToTSRAIR()(TSR AIR initialization). In installer mode, it hides the console window; in standalone command mode, it shows it.
DBConfiguration.CommonUtilities
InitializeDbToTSRAIR(string targetDir): Initializes the database to TSR AIR settings. Performs the following sequence:- Calls
ConfigInitializationHelper.UpdateTSRAIRAppSettings(targetDir, true)(not shown in source; assumed external). - Calls
Attach(targetDbDir, scriptsDir)to attach existing databases. - Calls
DbOperations.Connection.Initialize(InitializationTypes.TSRAIR, targetDir)(assumed external). - Calls
Detach(...)to detach the migrated databases. - Shows a success message box.
- Calls
Attach(string targetDbDir, string scriptsDir): Logs and sets migration status, then callsInstallDatabase(targetDbDir, "DataPRO", scriptsDir).InstallDatabase(string dBdir, string dbName, string scriptsDir): Performs full LocalDB instance setup:- Sets connection properties (
Server = Settings.Default.LocalDbDataPROInstance,NTLMAuthentication = true,usingCentralizedDB = false,usingMSSQL = true). - Executes SQL LocalDB commands via
ProcessSqlLocalDbCommand(...)to stop, delete, create, and start the LocalDB instance. - Attaches
DataPRO.mdfandISO.mdfdatabases usingAttachOrDetachDatabase(...)withSettings.Default.AttachDBsbat. - Returns any error output from SQL commands.
- Sets connection properties (
Detach(string sourceDbName, string targetDbDir, string scriptsDir): Detaches thesourceDbName(typically"DataPRO") andISOdatabases usingAttachOrDetachDatabase(...)withSettings.Default.DetachDBsbat. Logs status and shows warnings if errors occur.SetMigrationStatus(string migrationStatus, bool output = false): Creates and returns aMigrationStatusobject withStatusType = StatusTypes.MigrationStatusand the givenmigrationStatustext. Optionally writes toConsole.WriteLine.ProcessSqlLocalDbCommand(string command): Executes a command (e.g.,"start v14.0","create v14.0") against SQL Server LocalDB by:- Resolving the LocalDB installation path via
GetSqlServerLocalDBPath(). - Invoking
sqllocaldb.exeviaSqlCommandProcessor(...). - Returns non-empty string on error (e.g.,
"localdb not installed").
- Resolving the LocalDB installation path via
GetSqlServerLocalDBPath(): Queries the registry (HKLM\SOFTWARE\Microsoft\Microsoft SQL Server\LocalDB\Installed Versions) to find the highest installed LocalDB version with a validSqlUserInstance.dllpath. Returns the path to theToolsdirectory (e.g.,C:\Program Files\Microsoft SQL Server\140\Tools\).AttachOrDetachDatabase(string scriptsDir, string dbName, string sqlDbFileName, string sqlLogFileName, string attachOrDetach): Invokes a batch script (e.g.,AttachDBs.bat) viaBatchCommandProcessor(...). The batch script is expected to usesqlcmd.exeto executeCREATE DATABASE ... FOR ATTACH.SqlCommandProcessor(string sqlLocalDbExeFileName, string command): Executes a command-line process (sqllocaldb.exe) asynchronously, capturing output viaOutputHandler. Returns captured output if non-empty.BatchCommandProcessor(string batchFileName, string dbName, string sqlDbFileName, string sqlLogFileName, string fullSqlcmdPath): Executes a batch file with arguments:dbName, quoteddbFileName, quotedlogFileName, and quotedsqlcmd.exepath. Uses same async output capture mechanism.
Note
:
SetStatus(string status, bool output = false)is private and used internally; not part of the public interface.
3. Invariants
- LocalDB instance name: Hardcoded to
"DataPRO"inInstallDatabaseandAttach. Cannot be changed during TSR AIR Go installation. - Database files: Always expects
DataPRO.mdf/DataPRO.ldfandISO.mdf/ISO.ldfintargetDbDir. - Authentication: Uses NTLM authentication (
DbOperations._usingNTLMAuthentication = true) for all LocalDB operations. - Centralized DB flag:
DbOperations._usingCentralizedDBis explicitly set tofalseduring LocalDB operations. - Console visibility: In installer mode (
args.Length > 0andnoUI != "STANDALONECMD"), the console window is hidden (SW_HIDE). In standalone command mode (args.Length == 2), it is shown (SW_SHOW). - TSR AIR mode: When
tsrAirGo == true, the UI (DBTypeChoice) is skipped entirely. - Registry query: Only queries 64-bit registry view (
RegistryView.Registry64).
4. Dependencies
External Dependencies (from imports/includes):
System,System.Windows.Forms,System.Diagnostics,System.IO,System.Text,Microsoft.Win32DTS.Common.Storage,DTS.Common.Enums,DTS.Common.Utilities,DTS.Common.Utils.DatabaseDBConfiguration.Properties(forSettings.Default)
Internal Dependencies:
DBTypeChoice(Windows Form class, defined inDBTypeChoice.Designer.csand impliedDBTypeChoice.csnot provided).DbOperations(static class withConnectionand_usingCentralizedDB,_usingMSSQL,_usingNTLMAuthenticationfields; not shown but referenced).ConfigInitializationHelper(static class withUpdateTSRAIRAppSettings(...)method; not shown).Settings.Default: Used extensively for strings (e.g.,LocalDbFolder,ScriptsFolder,LocalDbDataPROInstance,Mdf,LogLdf,AttachDBsbat,DetachDBsbat,StopDataProInstance,DeleteDataProInstance,CreateDataProInstance,StartDataProInstance,ISO,SqlServerLocalDbNotInstalled,Warning,InstallationStatus,TSRAIRGoInstallationCompletedSuccessfully,AttachingPrevLocalDb,DetachingLocalMigratedDb,DetachingLocalISODb,AttachDBsbat,DetachDBsbat,RegistrySoftwareMicrosoftMicrosoftSQLServerLocalDBInstalledVersions,InstanceAPIPath,SqlUserInstanceDll,LocalDB,Tools,SqlLocalDBExe).
Dependencies on this module:
- The installer (likely WiX or similar) invokes
DBConfig.Main(...)with specific command-line arguments during installation. - Other modules may rely on
CommonUtilitiesfor database setup logic (though onlyInitializeDbToTSRAIRis called fromDBConfig).
5. Gotchas
- Hardcoded database name:
"DataPRO"is hardcoded inInstallDatabaseandAttach. Changing this requires updating multiple locations. - Registry path assumptions:
GetSqlServerLocalDBPath()assumes a specific registry path (...\LocalDB\Installed Versions) and that subkeys are version numbers (e.g.,"11.0","14.0"). Failure to parse a subkey as a double silently skips it. SqlUserInstanceDllcheck: Only considers versions where theInstanceAPIPathvalue ends with"SqlUserInstance.dll". If the path format changes, LocalDB resolution fails.- Console window toggling: The console window is hidden/shown based on
args.LengthandnoUIvalue. Misunderstanding the argument semantics may lead to unexpected UI behavior (e.g., window flashing). tsrAirGooverride: WhentsrAirGo == true, the entireDBTypeChoiceform is skipped—even ifnoUI != "TRUE". This may conflict with expectations ifnoUIis"TRUE"buttsrAirGois also set.- Error handling: Errors from SQL commands are returned as strings and displayed via
MessageBox.Show(...), but the method continues execution (e.g.,InstallDatabaseproceeds even ifProcessSqlLocalDbCommandreturns non-empty). This may leave the system in a partially configured state. sbstatic field:CommonUtilities.sbis a staticStringBuilderused for output capture. Concurrent calls toSqlCommandProcessororBatchCommandProcessor(if ever introduced) would interfere with each other.- Missing implementation details: Key dependencies like
DbOperations.Connection.Initialize(...),ConfigInitializationHelper.UpdateTSRAIRAppSettings(...), andSettings.Defaultvalues are referenced but not defined in the provided source. Their behavior is inferred but not verifiable here. - No rollback logic: If
Attachsucceeds butDetachfails, there is no cleanup or error recovery—databases remain attached until manually detached. ProcessSqlLocalDbCommandreturn value: Returns non-empty string on error, but callers treat any non-empty string as a warning (viaMessageBox.Show) and continue. This may mask critical failures.