Skip to contents

Opens database connection to MS Access or MS Excel, checks the connection and stops on error.

Usage

hsOpenDb(src, use2007Driver = NULL, dbg = FALSE, DBMSencoding = "", ...)

Arguments

src

full path to MS Access database file (extension “.mdb” or “.accdb”) or MS Excel file (extension “.xls” or “.xlsx”) or name of ODBC data source.

use2007Driver

if TRUE the functions odbcConnectAccess2007 and odbcConnectExcel2007 are used instead of odbcConnectAccess and odbcConnectExcel, respectively

dbg

if TRUE and if the connection could be established details of the connection are shown.

DBMSencoding

finally passed to odbcDriverConnect. Default: "", You may want to use: "UTF-8"

...

additional arguments passed to the odbcConnect...()-function

Value

On success an object of class RODBC describing the connection is returned. On failure nothing is returned and program execution stops.

See also

Examples

if (FALSE) { 
## Open a connection to the example database
## (only on Windows!)

if (.Platform$OS.type == "windows") {

  con <- hsOpenDb(xmdb())
  con
}
   
## Details on the established connection are shown:
# RODBC Connection 9
# Details:
#   case=nochange
#   DBQ=C:\Users\hsonne\Documents\R\win-library\2.14\kwb.base\...
#   Driver={Microsoft Access Driver (*.mdb)}
#   DriverId=25
#   FIL=MS Access
#   MaxBufferSize=2048
#   PageTimeout=5
#   UID=admin
  
## Close the connection again

if (.Platform$OS.type == "windows") {

  hsCloseDb(con)
}
}