r - 使用 R 中的 DBI 和 ActiveDirectoryPassword 身份验证连接到

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

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

运行下面的代码会导致错误:

DBI::dbConnect(
            odbc()
            , Driver = "SQL Server"
            , .connection_string = 
                    sprintf("server=%s;database=dbName;UID=%s;PWD=%s;Authentication=%s;"
                            , 'sqlservername.database.windows.net'
                            , '<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="b7ddc2c4c3ded9f7d4d8d9c3d8c4d899d4d8da" rel="noreferrer noopener nofollow">[email protected]</a>'
                            , 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.

我认为用户名中的 @ 的行为与我最初预期的不同。我该如何让这个连接发挥作用? - 我想我只需要找到正确的格式来表达(转义?)用户名。

最佳答案

这对我有用

DBI::dbConnect(
            odbc()
            , Driver = "SQL Server"
            , .connection_string = 
                    sprintf("server=%s;database=%s;UID=%s;PWD=%s;Authentication=%s;"
                            , 'sqlservername.database.windows.net'
                            , 'databasename'
                            , '<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="681d1b0d1a280b070518090611460b0705" rel="noreferrer noopener nofollow">[email protected]</a>'
                            , pwd # Let's just assume this is securely done for now
                            , 'ActiveDirectoryPassword'))

关于r - 使用 R 中的 DBI 和 ActiveDirectoryPassword 身份验证连接到 Azure SQL 数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54220239/

相关文章:

javascript - typescript 在不同类型的数组中查找

php - 如何为 Composer 创建分支别名并使用它?

azure - 确定特定 SessionId 的 Azure 服务总线队列上有多少消息

laravel - 错误 "Installation failed, reverting ./com

javascript - Webpack Import Code Splitting 渲染

performance - Html-Webpack-Plugin 在多个 pug 文件上非常慢

sql - Presto SQL 窗口聚合回顾 x 小时/分钟/秒

reactjs - 用于 Web 的 React 向上滑动面板

sql-server - 来自 Azure 网站的 Azure VM SQL Server Inte

mongodb - 蒙哥错误: cannot nest $ under $in