Learn R Programming

DBI (version 1.3.0)

dbCanConnect: Check if a connection to a DBMS can be established

Description

Like dbConnect(), but only checks validity without actually returning a connection object. The default implementation opens a connection and disconnects on success, but individual backends might implement a lighter-weight check.

DBI:::methods_as_rd("dbCanConnect")

Usage

dbCanConnect(drv, ...)

Value

A scalar logical. If FALSE, the "reason" attribute indicates a reason for failure.

Arguments

drv

An object that inherits from DBI::DBIDriver, or an existing DBI::DBIConnection object (in order to clone an existing connection).

...

Authentication arguments needed by the DBMS instance; these typically include user, password, host, port, dbname, etc. For details see the appropriate DBIDriver.

See Also

Other DBIDriver generics: DBIDriver-class, dbConnect(), dbDataType(), dbDriver(), dbGetInfo(), dbIsReadOnly(), dbIsValid(), dbListConnections()

Examples

Run this code
if (FALSE) { # requireNamespace("RSQLite", quietly = TRUE)
# SQLite only needs a path to the database. (Here, ":memory:" is a special
# path that creates an in-memory database.) Other database drivers
# will require more details (like user, password, host, port, etc.)
dbCanConnect(RSQLite::SQLite(), ":memory:")
}

Run the code above in your browser using DataLab