connectODBC: Connect to ODBC Database Using keyring

View source: R/connectODBC.R

connectODBCR Documentation

Connect to ODBC Database Using keyring

Description

[Stable]

Creates connection to ODBC database using the data contained in keyrings. This is generally used for internal purposes at MARC to make database connections a lazier proccess with keryring.

Usage

connectODBC(databaseString = NULL)

Arguments

databaseString

Same as the username saved in the keyring. Default NULL will list the available keys under the service 'DB_conn'

Details

Keys should be set up prior to using the function to a style similar to:

keyring::key_set("DB_conn", username = "<serverName>.<databaseName>.<userName>")

The password should then be set to the connection string formatted like:

"Driver={ODBC Driver 17 for SQL Server};Server=<serverName>;Database=<databaseName>;UID=<userName>;PWD=<password>;"

Leave the PWD section in the username argument written as PASSWORD as this is automatically replaced with the stored password when calling connectODBC().

Value

OBDC connection object returned from DBI::dbConnect()

Creation notes

First created in 2020-Sept for easily accessing databases in R

Author(s)

Jacob Peterson

Examples

## Not run: 
library(glue)
library(magrittr)
library(DBI)

con <- connectODBC("<serverName>.<databaseName>.<userName>")

DBI_getOBDCtable(con, "SELECT * FROM <schemaName>.<tableName>")

## End(Not run)

MARC-KC/marcR documentation built on June 2, 2022, 9:31 p.m.