Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.
Hi @Lukas2357,
What youโre seeing usually happens when the UDFโs connection alias is bound to the SQL endpoint of the Lakehouse instead of the Warehouse, even if the picker showed the Warehouse name. In practice, FabricSqlConnection can target both Warehouse and Lakehouse SQL endpoints, and a mismatched alias will make DB_NAME() read back the Lakehouse name. (docs: UDF programming model, docs: Connect to data sources). There have also been a few community reports of alias mix-ups that look exactly like this (example thread).
import fabric.functions as fn
udf = fn.UserDataFunctions()
@udf.connection(alias="wh_sales_dw", argName="sqlDB")
@udf.function()
def whoami(sqlDB: fn.FabricSqlConnection) -> str:
conn = sqlDB.connect()
with conn.cursor() as cur:
cur.execute("SELECT DB_NAME(), @@VERSION;")
db_name, version = cur.fetchone()
return db_nameIf you found this helpful, consider giving some Kudos. If I answered your question or solved your problem, mark this post as the solution.
Thanks for the reply. In fact the reddit thread is describing the exact same issue and it was not solved for several months. I tried your suggested solution, but found the same error. Below you see I tested the function against a lakehouse and warehouse connection and both returned the lakehouse. It seems the selected endpoint and related artifact from the workspace is arbitrary. To me it seems like a bug that needs to be fixed to use data functions properly.
Hi @Lukas2357,
Facinating, my fix worked in my tenant, but I agree that there is a bug here. Maybe the bug is tenant dependant and only affecting some users?
I'd recommend opening a support ticket with Microsoft to raise this as a bug with the product team.
If you found this helpful, consider giving some Kudos. If I answered your question or solved your problem, mark this post as the solution.
Hi @Lukas2357,
Thank you for reaching out to the Microsoft Fabric Community Forum and sharing the details and your code snippet. Also, thanks to @tayloramy, for his inputs on this thread.
What you are seeing is a known behaviour in Microsoft Fabric. Even when a warehouse is explicitly selected in the UDF connection, sometimes the function defaults to the Lakehouse SQL endpoint. This happens because the connection alias might still be pointing to the Lakehouse behind the scenes, even if the UI shows your warehouse. That is why DB_NAME() returns the Lakehouse name.
Create separate connections for the Lakehouse and warehouse: Go to the Functions โ Manage connections pane. Create one connection for your warehouse and another for the Lakehouse SQL endpoint. Give them clear aliases, e.g., wh_sales_dw for the warehouse.
Update Your UDF: Modify your UDF code to use the warehouse alias.
import fabric.functions as fn
udf = fn.UserDataFunctions()
@udf.connection(alias="wh_sales_dw", argName="sqlDB")
@udf.function()
def whoami(sqlDB: fn.FabricSqlConnection) -> str:
conn = sqlDB.connect()
with conn.cursor() as cur:
cur.execute("SELECT DB_NAME(), @@VERSION;")
db_name, version = cur.fetchone()
return db_name
Republish and test: now it should return your warehouse name instead of the Lakehouse.
Refer these links:
1. https://learn.microsoft.com/en-us/fabric/data-engineering/user-data-functions/connect-to-data-source...
2. https://learn.microsoft.com/en-us/fabric/data-engineering/user-data-functions/python-programming-mod...
Hope this helps get you unblocked! Please keep us posted on the results so we can assist further if needed.
Thank you for using the Microsoft Fabric Community Forum.
Hi @Lukas2357,
Just checking in to see if the issue has been resolved on your end. If the earlier suggestions helped, thatโs great to hear! And if youโre still facing challenges, feel free to share more details happy to assist further.
Thank you.
| User | Count |
|---|---|
| 11 | |
| 6 | |
| 3 | |
| 3 | |
| 3 |