-
Notifications
You must be signed in to change notification settings - Fork 50
Fabric Connection Strings #349
Copy link
Copy link
Closed
Labels
area: connectivity-authConnection lifecycle, Entra/SP/NTLM auth, tokens, TLS, conn-string parsing, Fabric endpoints.Connection lifecycle, Entra/SP/NTLM auth, tokens, TLS, conn-string parsing, Fabric endpoints.enhancementNew feature or requestNew feature or requestpr-size: mediumModerate update sizeModerate update sizequestionFurther information is requestedFurther information is requestedtriage doneIssues that are triaged by dev team and are in investigation.Issues that are triaged by dev team and are in investigation.
Metadata
Metadata
Assignees
Labels
area: connectivity-authConnection lifecycle, Entra/SP/NTLM auth, tokens, TLS, conn-string parsing, Fabric endpoints.Connection lifecycle, Entra/SP/NTLM auth, tokens, TLS, conn-string parsing, Fabric endpoints.enhancementNew feature or requestNew feature or requestpr-size: mediumModerate update sizeModerate update sizequestionFurther information is requestedFurther information is requestedtriage doneIssues that are triaged by dev team and are in investigation.Issues that are triaged by dev team and are in investigation.
Type
Fields
Give feedbackNo fields configured for Feature.
Is your feature request related to a problem? Please describe.
After reading this thread: https://www.reddit.com/r/MicrosoftFabric/comments/1p5oduh/mssqlpython_with_pandas_or_polars_warnings_and/, I think we have an opportunity to improve the experience.
The current experience using mssql-python with Fabric Notebooks has a ton of friction. Here's an example:
`import struct
import mssql_python
import pandas as pd
connection_string = (
f"Server={server};"
f"Database={database};"
"Encrypt=yes;"
)
access_token = notebookutils.credentials.getToken('pbi')
token = access_token.encode("UTF-16-LE")
token_struct = struct.pack(f'<I{len(token)}s', len(token), token)
SQL_COPT_SS_ACCESS_TOKEN = 1256
connection = mssql_python.connect(connection_string, attrs_before={SQL_COPT_SS_ACCESS_TOKEN: token_struct})
tables = ["Customers", "Invoices", "Orders"]
for table in tables:
query = f"SELECT TOP 5 * FROM Sales.{table}"
pd_data = pd.read_sql_query(query, connection)
Close the connection
connection.close()`
Describe the solution you'd like
We could improve on this quite a bit by adding a Fabric Notebook connection option and allowing worskpace and database name to be passed like it is with tsql magic in Fabric Notebooks. Here's an example:
`import struct
import mssql_python
import pandas as pd
connection_string = (
f"Workspace={workspace};"
f"Database={database};"
"Authentication=FabricNotebook;"
"Encrypt=yes;"
)
connection = mssql_python.connect(connection_string)
tables = ["Customers", "Invoices", "Orders"]
for table in tables:
query = f"SELECT TOP 5 * FROM Sales.{table}"
pd_data = pd.read_sql_query(query, connection)
Close the connection
connection.close()`
Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.
Additional context
This seems to be a fairly standard pattern: https://www.reddit.com/r/MicrosoftFabric/comments/1p6mkn3/connect_to_fabric_warehouse_from_python_notebook/