{"record":{"id":"26fe17690961ea72","repo":"SeaQL/sea-orm","slug":"disconnected-26fe17","errorCode":null,"errorMessage":"Disconnected","messagePattern":"Disconnected","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"src/database/db_connection.rs","lineNumber":727,"sourceCode":"    ///\n    /// # Panics\n    ///\n    /// Panics if [DatabaseConnection] is `Disconnected`.\n    pub fn get_database_backend(&self) -> DbBackend {\n        match &self.inner {\n            #[cfg(feature = \"sqlx-mysql\")]\n            DatabaseConnectionType::SqlxMySqlPoolConnection(_) => DbBackend::MySql,\n            #[cfg(feature = \"sqlx-postgres\")]\n            DatabaseConnectionType::SqlxPostgresPoolConnection(_) => DbBackend::Postgres,\n            #[cfg(feature = \"sqlx-sqlite\")]\n            DatabaseConnectionType::SqlxSqlitePoolConnection(_) => DbBackend::Sqlite,\n            #[cfg(feature = \"rusqlite\")]\n            DatabaseConnectionType::RusqliteSharedConnection(_) => DbBackend::Sqlite,\n            #[cfg(feature = \"mock\")]\n            DatabaseConnectionType::MockDatabaseConnection(conn) => conn.get_database_backend(),\n            #[cfg(feature = \"proxy\")]\n            DatabaseConnectionType::ProxyDatabaseConnection(conn) => conn.get_database_backend(),\n            DatabaseConnectionType::Disconnected => panic!(\"Disconnected\"),\n        }\n    }\n\n    /// Creates a [`SchemaBuilder`] for this backend\n    pub fn get_schema_builder(&self) -> SchemaBuilder {\n        Schema::new(self.get_database_backend()).builder()\n    }\n\n    #[cfg(feature = \"entity-registry\")]\n    #[cfg_attr(docsrs, doc(cfg(feature = \"entity-registry\")))]\n    /// Builds a schema for all the entites in the given module\n    pub fn get_schema_registry(&self, prefix: &str) -> SchemaBuilder {\n        let schema = Schema::new(self.get_database_backend());\n        crate::EntityRegistry::build_schema(schema, prefix)\n    }\n\n    /// Sets a callback to metric this connection\n    pub fn set_metric_callback<F>(&mut self, _callback: F)","sourceCodeStart":709,"sourceCodeEnd":745,"githubUrl":"https://github.com/SeaQL/sea-orm/blob/e29bcd1b417c41a553b386fe94511d7c64a1c8ec/src/database/db_connection.rs#L709-L745","documentation":"This panic fires when `get_database_backend()` (or a similar backend-inspecting method) is called on a `DatabaseConnection` whose inner `DatabaseConnectionType` is the `Disconnected` variant. SeaORM represents an un-established, closed, or never-connected connection this way, and there is no backend to report for a connection that was never opened. It is a hard panic, not a recoverable `Result`, because the API contract assumes a live connection.","triggerScenarios":"Calling `get_database_backend()`, `get_schema_builder()`, or any backend-querying method on a `DatabaseConnection` created via `DatabaseConnection::default()` / `Disconnected`, or after the connection was explicitly disconnected/replaced with a disconnected handle.","commonSituations":"Declaring a `DatabaseConnection::default()` struct field and using it before `connect()` succeeds; storing the connection after `connect()` returned an `Err` but the error was swallowed with `.unwrap_or_default()`; using a connection whose pool was shut down in tests.","solutions":["Ensure `DatabaseConnection::connect(...)` is awaited and its `Result` is propagated before any query or backend query; never use `.unwrap_or_default()` on connect.","Check `conn.is_valid()` / match on `DatabaseConnectionType` before calling backend-dependent methods.","Initialize the connection in application setup (e.g. actix `web::Data`) so handlers only ever receive a connected handle.","If lazily initializing, gate access behind an `Option<DatabaseConnection>` or `OnceCell` so a disconnected handle can't be reached."],"exampleFix":"// before\nlet db: DatabaseConnection = DatabaseConnection::default();\nlet backend = db.get_database_backend(); // panics: Disconnected\n\n// after\nlet db = Database::connect(\"sqlite://db.sqlite?mode=rwc\").await?;\nlet backend = db.get_database_backend(); // safe: connection is live","handlingStrategy":"validation","validationCode":"if !conn.is_valid() || matches!(conn, DatabaseConnection { inner: DatabaseConnectionType::Disconnected, .. }) {\n    return Err(anyhow!(\"database connection not established\"));\n}","typeGuard":"fn is_connected(conn: &DatabaseConnection) -> bool {\n    !matches!(conn.as_ref(), DatabaseConnectionType::Disconnected)\n}","tryCatchPattern":null,"preventionTips":["Always propagate the Result of Database::connect; never unwrap_or_default.","Store the connection in app state only after a successful connect.","Call is_valid()/ping before first use in long-running processes.","Wrap lazy connections in Option/OnceCell so a disconnected handle is unreachable."],"tags":["panic","connection","initialization","database"],"backgroundTag":"connection-refused","analyzedSha":"e29bcd1b417c41a553b386fe94511d7c64a1c8ec","analyzedAt":"2026-09-10T11:31:52.468Z","contentChangedAt":"2026-09-10T11:31:52.468Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}