Based on this question I've built the following function, which seems to connect to the SQL Server but is unable to authenticate:
connect <- function(server, database, user, password){
# Autoinstall if necessary
packages <- c("RJDBC")
new.packages <- packages[!(packages %in% installed.packages()[, "Package"])]
if(length(new.packages)){
install.packages(new.packages, dependencies = TRUE)
}
library(RJDBC)
sql.java <- paste(find.package(package = 'mypackage'), '/sqljdbc4.jar', sep = "")
drv <- JDBC("com.microsoft.sqlserver.jdbc.SQLServerDriver",
sql.java,
identifier.quote = "`")
con.string <- paste("jdbc:sqlserver://", server, ";databaseName=", database, ";integratedSecurity=true;", sep = "")
con <- dbConnect(drv, con.string, user, password)
}
# Feb 24, 2015 9:57:56 AM com.microsoft.sqlserver.jdbc.AuthenticationJNI <clinit>
# WARNING: Failed to load the sqljdbc_auth.dll cause : no sqljdbc_auth in java.library.path
# Show Traceback
# Rerun with Debug
# Error in .jcall(drv@jdrv, "Ljava/sql/Connection;", "connect", as.character(url)[1], :
# com.microsoft.sqlserver.jdbc.SQLServerException: This driver is not configured for integrated authentication. ClientConnectionId:5ac4ed9c-a4a8-4318-ba77-7f3fb2ed01b0
# If I take ;integratedSecurity=true out of there:
# Error in .jcall(drv@jdrv, "Ljava/sql/Connection;", "connect", as.character(url)[1], :
# com.microsoft.sqlserver.jdbc.SQLServerException: Login failed for user 'domain\user'. ClientConnectionId:29035eb6-7b9f-4d9c-86b4-6d6760c61399
Does anyone know how I can handle authentication? It seems to work with RODBC on my Windows machine.