build_connection_string: Build a connection string for use with MSSQL and dbConnect

Description Usage Arguments Value See Also Examples

View source: R/db_connections.R

Description

Handy utility to build a connection string to pass into DBI::dbConnect. Accepts trusted connections or username/password.

Usage

1
2
build_connection_string(server, driver = "SQL Server", database,
  trusted = TRUE, user_id, password)

Arguments

server

A string, quoted, required. The name of the server you are trying to connect to.

driver

A string, quoted, optional. Defaults to "SQL Server", but use any driver you like.

database

A string, quoted, optional. If provided, connection string will include a specific database. If NA (default), it will connect to master and you'll have to specify the database when running a query.

trusted

Logical, optional, defaults to TRUE. If FALSE, you must use a user_id and password.

user_id

A string, quoted, optional. Don't include if using trusted.

password

A string, quoted, optional. Don't include if using trusted.

Value

A connection string

See Also

db_read

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
## Not run: 
my_con <- build_connection_string(server = "localhost")
con <- DBI::dbConnect(odbc::odbc(), .connection_string = my_con)

# with username and password
my_con <- build_connection_string(server = "localhost",
                                  user_id = "jules.winnfield",
                                  password = "pathoftherighteous")
con <- DBI::dbConnect(odbc::odbc(), .connection_string = my_con)

## End(Not run)

healthcareai documentation built on Sept. 2, 2018, 1:03 a.m.