--- title: "Connections and dependencies" output: rmarkdown::html_vignette vignette: > %\VignetteIndexEntry{Connections and dependencies} %\VignetteEngine{knitr::rmarkdown} %\VignetteEncoding{UTF-8} --- `db_connect` and the deprecated `dbConnect` alias are exported. They open a connection only when called. The caller owns it and must close it with `DBI::dbDisconnect`. PostgreSQL requires RPostgres; SQL Server requires odbc and an installed driver. Additional options such as `sslmode` reach the driver. Do not repeat names already supplied by the wrapper. SQL Server accepts an alternative `Driver`; a trusted connection neither looks up passwords nor sends UID/PWD. With `trusted_connection = FALSE`, credentials use those names. The historical keyring service default remains `postgre`. Explicit credentials take precedence. To use explicit arguments or driver configuration, set `k_service_id = NULL`. If a service contains multiple accounts, supply `db_user`: account order never determines the selected identity. Tests verify argument forwarding with test doubles, a fictional keyring and an in-memory SQLite database. No real PostgreSQL or SQL Server authentication was performed. The [DBI](https://dbi.r-dbi.org/reference/dbConnect.html) and [RPostgres](https://rpostgres.r-dbi.org/reference/Postgres.html) references describe their driver contracts. Legacy database names `enft1` and `enft2` map to `enft` with a warning. The `dbConnect` alias retains its deprecation and now forwards additional options. ```{r} library(Dmisc) stopifnot(all(c("db_connect", "dbConnect") %in% getNamespaceExports("Dmisc"))) # Explicit connection template; no authentication is executed by this example. if (FALSE) { con <- db_connect(db_name = "example", k_service_id = NULL, sslmode = "require") DBI::dbDisconnect(con) } ```