View source: R/connect_nhsbsa.R
con_nhsbsa | R Documentation |
Connect to NHSBSA DB from the Bastion Host. Hopefully you will already have the ODBC driver installed, but if not you may have to raise a service request with IT.
con_nhsbsa(
dsn = "FBS_8192k",
driver = "Oracle in OraClient19Home1",
database,
username = toupper(Sys.getenv(paste0("DB_", database, "_USERNAME"))),
password = Sys.getenv(paste0("DB_", database, "_PASSWORD"))
)
dsn |
Default is "FBS_8192k" with Fetch Buffer Size of 8192k created for us by Platform Services on Azure VDs. If, for some reason, this DSN is unavailable on your VD, set this to NULL in order to use the default "Oracle in OraClient19Home1" driver with default settings. |
driver |
String, ODBC driver to connect to the DB. Default is correct but an argument is provided in case this ever changes. |
database |
String, name of the DB - one of c("DALP", "DWCP")). |
username |
String, username for DB. Default value is
|
password |
String, username for DB. Default value is
|
Connection to DB. Note: When finished close your connection using
DBI::dbDisconnect()
# Initialise connection assuming you have a `.Renviron` file with
# DB_DALP_USERNAME and DB_DALP_PASSWORD set (recommended)
## Not run:
con <- nhsbsaR::con_nhsbsa(database = "DALP")
## End(Not run)
# Initialise connection without `.Renviron` file (Note: Never store passwords
# in your code)
## Not run:
con <- nhsbsaR::con_nhsbsa(
database = "DWCP",
username = rstudioapi::showPrompt(),
password = rstudioapi::askForPassword()
)
## End(Not run)
# Boring DBI methods...
## Not run:
DBI::dbGetQuery(conn = con, statement = "SELECT * FROM dual")
DBI::dbReadTable(conn = con, name = "DUAL") # Case sensitive in ODBC
## End(Not run)
# Cool dbplyr methods... (see https://dbplyr.tidyverse.org)
## Not run:
dplyr::tbl(src = con, from = "DUAL") # Case sensitive in ODBC
dplyr::tbl(src = con, from = dbplyr::in_schema(schema = "SYS", table = "DUAL") # Case sensitive in ODBC
dplyr::tbl(src = con, from = dbplyr::sql("SELECT * FROM dual"))
## End(Not run)
# Remember to disconnect your session
## Not run:
DBI::dbDisconnect(con)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.