{"record":{"id":"a94fe998150fd95a","repo":"Sonarr/Sonarr","slug":"unable-to-determine-database-connection-string-for","errorCode":null,"errorMessage":"Unable to determine database connection string for type {0}.","messagePattern":"Unable to determine database connection string for type (.+?)\\.","errorType":"exception","errorClass":"SonarrStartupException","httpStatus":null,"severity":"critical","filePath":"src/NzbDrone.Core/Datastore/ConnectionStringFactory.cs","lineNumber":43,"sourceCode":"\n            var connectionStringType = GetConnectionStringType();\n\n            switch (connectionStringType)\n            {\n                case ConnectionStringType.PostgreSqlVars:\n                    MainDbConnection = GetPostgresConnectionString(_configFileProvider.PostgresMainDb);\n                    LogDbConnection = GetPostgresConnectionString(_configFileProvider.PostgresLogDb);\n                    break;\n                case ConnectionStringType.PostgreSqlConnectionString:\n                    MainDbConnection = GetPostgresConnectionInfoFromConnectionString(_configFileProvider.PostgresMainDbConnectionString);\n                    LogDbConnection = GetPostgresConnectionInfoFromConnectionString(_configFileProvider.PostgresLogDbConnectionString);\n                    break;\n                case ConnectionStringType.Sqlite:\n                    MainDbConnection = GetConnectionString(appFolderInfo.GetDatabase());\n                    LogDbConnection = GetConnectionString(appFolderInfo.GetLogDatabase());\n                    break;\n                default:\n                    throw new SonarrStartupException(\"Unable to determine database connection string for type {0}.\", connectionStringType.ToString());\n            }\n        }\n\n        public DatabaseConnectionInfo MainDbConnection { get; private set; }\n        public DatabaseConnectionInfo LogDbConnection { get; private set; }\n\n        public string GetDatabasePath(string connectionString)\n        {\n            var connectionBuilder = new SQLiteConnectionStringBuilder(connectionString);\n\n            return connectionBuilder.DataSource;\n        }\n\n        private static DatabaseConnectionInfo GetConnectionString(string dbPath)\n        {\n            var connectionBuilder = new SQLiteConnectionStringBuilder\n            {\n                DataSource = dbPath,","sourceCodeStart":25,"sourceCodeEnd":61,"githubUrl":"https://github.com/Sonarr/Sonarr/blob/da2284d7eaab22ed9b2ca698af690148d691e967/src/NzbDrone.Core/Datastore/ConnectionStringFactory.cs#L25-L61","documentation":"Thrown by the ConnectionStringFactory constructor's switch default as a SonarrStartupException. It fires only if GetConnectionStringType returned an enum value not handled by the three cases. Because the private ConnectionStringType enum has exactly three members (Sqlite, PostgreSqlVars, PostgreSqlConnectionString) and GetConnectionStringType only ever returns those, this branch is effectively unreachable defensive code. Also note the message uses a literal '{0}' that the args-based formatter should interpolate but the wording is misleading.","triggerScenarios":"Practically unreachable: would require a future enum member added without a matching case, or reflection/serialization forcing an out-of-range enum value into the switch. Triggering it indicates a code bug rather than a configuration issue.","commonSituations":"Only seen if the source is patched to add a new ConnectionStringType without updating the switch, or an invalid enum value is injected via test tooling.","solutions":["Treat as a code defect: ensure every ConnectionStringType enum member has a case in the switch.","Replace the default with an explicit exhaustive switch or switch expression so the compiler flags missing cases.","If hit in production, review recent source changes to the enum or GetConnectionStringType.","Report as a bug; no user configuration produces this."],"exampleFix":"// before: default branch masks a missing case\nswitch (connectionStringType) {\n  case PostgreSqlVars: ...\n  case PostgreSqlConnectionString: ...\n  case Sqlite: ...\n  default: throw new SonarrStartupException(\"Unable to determine ... {0}\", connectionStringType.ToString());\n}\n\n// after: exhaustive switch expression, compiler enforces completeness\nMainDbConnection = connectionStringType switch {\n  ConnectionStringType.PostgreSqlVars => GetPostgresConnectionString(_configFileProvider.PostgresMainDb),\n  ConnectionStringType.PostgreSqlConnectionString => GetPostgresConnectionInfoFromConnectionString(_configFileProvider.PostgresMainDbConnectionString),\n  ConnectionStringType.Sqlite => GetConnectionString(appFolderInfo.GetDatabase()),\n  _ => throw new SonarrStartupException($\"Unable to determine database connection string for type {connectionStringType}.\")\n};","handlingStrategy":"validation","validationCode":"// Unreachable in practice; defensive compile-time check instead.\n// Use an exhaustive switch expression so a missing enum case is a build error:\n_ = connectionStringType switch\n{\n    ConnectionStringType.Sqlite => true,\n    ConnectionStringType.PostgreSqlVars => true,\n    ConnectionStringType.PostgreSqlConnectionString => true,\n    _ => throw new InvalidOperationException($\"Unhandled {nameof(ConnectionStringType)}: {connectionStringType}\")\n};","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Prefer exhaustive switch expressions over switch-with-default for enums so the compiler flags gaps.","Add unit tests covering every enum member when extending ConnectionStringType.","Treat this exception as a code bug, not a runtime config issue."],"tags":["database","startup","unreachable","dead-code"],"backgroundTag":null,"analyzedSha":"da2284d7eaab22ed9b2ca698af690148d691e967","analyzedAt":"2026-08-13T15:53:02.562Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}