使用R和ActiveDirectoryPassword身份验证中的DBI连接到Azure SQL数据库

时间:2019-01-16 15:22:31

标签: r azure odbc azure-sql-database dbi

我想使用R中的DBI连接到AzureSQL数据库。我想通过AzureAD ActiveDirectoryPassword身份验证来管理此连接。这要求我声明AzureAD UIDPassword

我已经确认可以使用其他身份验证方法连接到该服务器。

运行以下代码会导致错误:

DBI::dbConnect(
            odbc()
            , Driver = "SQL Server"
            , .connection_string = 
                    sprintf("server=%s;database=dbName;UID=%s;PWD=%s;Authentication=%s;"
                            , 'sqlservername.database.windows.net'
                            , 'justin@contoso.com'
                            , pwd # Let's just assume this is securely done for now
                            , 'ActiveDirectoryPassword'))

预期结果是连接到数据库

实际结果如下:

Error: nanodbc/nanodbc.cpp:950: HY000: [Microsoft][ODBC SQL Server Driver][SQL Server]Cannot open server "contoso.com" requested by the login.  The login failed.

我认为用户名中的@并不像我最初期望的那样。如何使该连接正常工作? -我想我只需要找到正确的格式来表示(转义?)用户名即可。

0 个答案:

没有答案