View source: R/fabric_sql_connect.R
| fabric_sql_connect | R Documentation |
Opens a DBI/ODBC connection to a Microsoft Fabric Data Warehouse or Lakehouse SQL endpoint, authenticating with Azure AD (MSAL v2) and passing an access token to the ODBC driver.
fabric_sql_connect(
server,
database = "Lakehouse",
tenant_id = Sys.getenv("FABRICQUERYR_TENANT_ID"),
client_id = Sys.getenv("FABRICQUERYR_CLIENT_ID", unset =
"04b07795-8ddb-461a-bbee-02f9e1bf7b46"),
access_token = NULL,
odbc_driver = getOption("fabricqueryr.sql.driver", "ODBC Driver 18 for SQL Server"),
port = 1433L,
encrypt = "yes",
trust_server_certificate = "no",
timeout = 30L,
verbose = TRUE,
...
)
server |
Character. Microsoft Fabric SQL connection string or |
database |
Character. Database name. Defaults to |
tenant_id |
Character. Entra ID (AAD) tenant GUID. Defaults to
|
client_id |
Character. App registration (client) ID. Defaults to
|
access_token |
Optional character. If supplied, use this bearer token
instead of acquiring a new one via |
odbc_driver |
Character. ODBC driver name. Defaults to
|
port |
Integer. TCP port (default 1433). |
encrypt, trust_server_certificate |
Character flags passed to ODBC.
Defaults |
timeout |
Integer. Login/connect timeout in seconds. Default 30. |
verbose |
Logical. Emit progress via |
... |
Additional arguments forwarded to |
server is the Microsoft Fabric SQL connection string, e.g.
"xxxx.datawarehouse.fabric.microsoft.com".
You can find this by going to your Lakehouse or Data Warehouse item,
then Settings -> SQL analytics endpoint -> SQL connection string.
You may also pass a DSN-less Server=... string; it will be normalized.
By default we request a token for
https://database.windows.net/.default.
AzureAuth is used to acquire the token. Be wary of
caching behavior; you may want to call AzureAuth::clean_token_directory()
to clear cached tokens if you run into issues
A live DBIConnection object.
# Example is not executed since it requires configured credentials for Fabric
## Not run:
con <- fabric_sql_connect(
server = "2gxz...qiy.datawarehouse.fabric.microsoft.com",
database = "Lakehouse",
tenant_id = Sys.getenv("FABRICQUERYR_TENANT_ID"),
client_id = Sys.getenv("FABRICQUERYR_CLIENT_ID")
)
# List databases
DBI::dbGetQuery(con, "SELECT name FROM sys.databases")
# List tables
DBI::dbGetQuery(con, "
SELECT TABLE_SCHEMA, TABLE_NAME
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_TYPE = 'BASE TABLE'
")
# Get a table
df <- DBI::dbReadTable(con, "Customers")
dplyr::glimpse(df)
DBI::dbDisconnect(con)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.