Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Querying a SQL Server database requiring MFA over RJDBC #94

Open
aaelony-aeg opened this issue Jul 13, 2022 · 1 comment
Open

Querying a SQL Server database requiring MFA over RJDBC #94

aaelony-aeg opened this issue Jul 13, 2022 · 1 comment

Comments

@aaelony-aeg
Copy link

Querying SQL via ODBC with MS-SQL Server is not supported on MacOs using MFA (see the Microsoft ODBC driver feature matrix). According to the same document, JDBC is supported.

How to connect to a MS-SQL Server database using RJDBC and MFA?

MFA appears to require MSAL4J to enable MFA. In any case, configuration is not intuitive or trivial, though apparently possible.

A skeleton so far is:

library(rJava)
library(RJDBC)

## ---- Set up the Driver variable
drv <- JDBC(
  driverClass = "com.microsoft.sqlserver.jdbc.SQLServerDriver", 
  classPath = "/Users/myusername/sqljdbc_10.2_enu/mssql-jdbc-10.2.1.jre17.jar",
  identifier.quote="`")

conn <- dbConnect(
  drv, 
  url = "jdbc:sqlserver://MY_SERVER_NAME;Encrypt=true;TrustServerCertificate=false;Connection Timeout=30;Authentication=ActiveDirectoryInteractive",
 "my_user_name",
  rstudioapi::askForPassword("Database password")
)

this almost works:

Error in dbConnect(drv, url = ...
Unable to connect JDBC to jdbc:sqlserver:// ...
JDBC ERROR: Failed to load MSAL4J Java library for performing ActiveDirectoryInteractive authentication.

So, this is close but unclear how to correctly include the MFA java library at this point.

Any recommendations ?

Perhaps how to include an arbitrary maven artifact from RJDBC like

<dependency>
    <groupId>com.microsoft.azure</groupId>
    <artifactId>msal4j</artifactId>
    <version>1.13.0</version>
</dependency>

??

thanks in advance

@aaelony-aeg
Copy link
Author

Update: I am able to query using Clojure or Java via MFA but some needed dependencies are:

        com.github.seancorfield/next.jdbc {:mvn/version "1.2.780"}
        com.microsoft.sqlserver/mssql-jdbc {:mvn/version "10.2.1.jre17"}
        com.microsoft.azure/msal4j {:mvn/version "1.13.0"}

How to bundle these on the classpath and use with RJDBC ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant