get_sqlserver_connection: Connect to a SQL Server database

View source: R/database.R

get_sqlserver_connectionR Documentation

Connect to a SQL Server database

Description

This function initiates a SQL Server connection using windows authentication, either using stored database credentials through the keyring package or else requesting database credentials in the console.

Usage

get_sqlserver_connection(keyring_name, service_name, keyring = TRUE)

Arguments

keyring_name

A character string providing the name of the keyring.

service_name

A character string providing the name of the key.

keyring

default TRUE uses the keyring, FALSE requests credentials.

Value

A SQL Server database connection object.

Connect

library(DBI)
library(odbc)

# connect to database, using keyring stored credentials
con <- get_sqlserver_connection(keyring_name = "keyring_name",
                                service_name = "database_name",
                                keyring = TRUE)

Query

More information on working with databases using R can be found in RStudio's Databases using R webpages.

# list tables
dbListTables(con)

# get table
database_table <- tbl(con, "table_name") %>% collect()

# get query
database_query <- dbGetQuery(con, "sql_statement")
database_query <- tbl(con, sql("sql_statement")) %>% collect()

Disconnect

dbDisconnect(con)

See Also

Other database functions: get_mysql_connection(), get_postgres_connection()


gcfrench/store documentation built on May 17, 2024, 5:52 p.m.