RSQLServer (version 0.3.0)

SQLServer: SQLServerDriver class and methods

Description

SQLServer() creates a SQLServerDriver object and is based on the jTDS driver while dbConnect() provides a convenient interface to connecting to a SQL Server database using this driver.

Usage

SQLServer()

# S4 method for SQLServerDriver dbConnect(drv, server, file = NULL, database = NULL, type = NULL, port = NULL, properties = NULL)

Arguments

drv

An objected of class , or an existing . If a connection, the connection will be cloned.

server

the server address or recognised alias thereof.

file

defaults to using the server details file in $HOME/sql.yaml. The server details including type, port and any optional properties can be sourced from this file. If the server name is found in file, the details therein are used (and in particular, those provided in other arguments to this function are ignored). The connection method prefers server details to be provided in a "sql.yaml" file rather than provided as arguments to this function. If you wish to specify the details as parameters, ensure that either the file does not exist or that the server details are not in the YAML file.

database

the name of the database hosted on the server. If an empty string or NULL (default), a connection to the default database on server is assumed.

type

the server type. Must be either "sqlserver" or "sybase". Defaults to "sqlserver" when set to NULL.

port

the TCP/IP default port. This will be coerced to a string. Defaults to 1433 if set to NULL or an empty string (jTDS behaviour).

properties

One or more optional connection properties. in a named list (defaults to empty list). Note if you intend to set the useNTLMv2 property to 'true' from the default API value of 'false', you will need to make a specific authentication driver available to the SQL Server driver, although this has not worked particularly well in testing. See RSQLServer for more details. Should you wish to use Windows authentication to connect to the server, I recommend you set the following optional parameters: set useNTLMv2 to 'true', domain to your domain and user and password to your username and password on domain. jTDS' SSO functionality is flaky.

Value

SQLServer() returns an object of class SQLServerDriver; dbConnect() returns a object.

References

jTDS API doc for Driver class

Examples

Run this code

SQLServer()

# View sql.yaml file bundled in package
file <- system.file("extdata", "sql.yaml", package = "RSQLServer")
readLines(file)
# Connect using ~/sql.yaml file

if (have_test_server()) {
 dbConnect(RSQLServer::SQLServer(), "TEST")
}
# Example where ~/sql.yaml does not exist or where the server
# is not in the YAML file.
dbConnect(RSQLServer::SQLServer(), server="11.1.111.11", port=1434,
   properties=list(useNTLMv2="true", domain="myco", user="me",
     password="asecret"))

Run the code above in your browser using DataLab