Fabric Connection Strings #358
dlevy-msft-sql
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
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/
Beta Was this translation helpful? Give feedback.
All reactions