Forum Discussion
How to set default Lakehouse in the notebook programmatically?
- Anonymous2 years ago
Hi keataunooi
Thanks for using Fabric Community.
To programmatically attach a lakehouse for a session level, you can use this below code in your notebook:# Welcome to your new notebook # Type here in the cell editor to add code! %%configure { "defaultLakehouse": { # This overwrites the default lakehouse for current session "name": "your-lakehouse-name", #"id": "<(optional) lakehouse-id>", #"workspaceId": "<(optional) workspace-id-that-contains-the-lakehouse>" # Add workspace ID if it's from another workspace } }
Hope this helps. Please let me know if you have any further questions.
Hi keataunooi
Thanks for using Fabric Community.
To programmatically attach a lakehouse for a session level, you can use this below code in your notebook:
# Welcome to your new notebook
# Type here in the cell editor to add code!
%%configure
{
"defaultLakehouse": { # This overwrites the default lakehouse for current session
"name": "your-lakehouse-name",
#"id": "<(optional) lakehouse-id>",
#"workspaceId": "<(optional) workspace-id-that-contains-the-lakehouse>" # Add workspace ID if it's from another workspace
}
}
Hope this helps. Please let me know if you have any further questions.
- keataunooi2 years agoRegular Visitor
Thanks. just tested the code you provided. it works.
I also figure out the default lakehouse of the notebook can be overriden by the pipeline deployment rules
Thanks again!
- Anonymous2 years agoNot applicable
Hi keataunooi
Glad that your query got resolved. Please continue using Fabric Community for any help regarding your queries.
- Anonymous2 years agoNot applicable
Hi Anonymous
If I have a Lakehouse with the same name both in Dev and in Prod workspaces, this code will attach the corresponding Lakehouse , if I do not specify Workspace ID ?
- srinivas11251 year agoNew Member
Even I have the same question. Does it attach lakehouse from the current workspace in case workspaceid is not mentioned?
And also does the notebook use other lakehouses of current workspace in SparkSQL ?
- lyjavier1 year agoHelper I
But is that I have to have this cell at first in the notebook?
- raviraoin1 year agoRegular Visitor
Thanks for sharing!
The approach works when you need to attach a single lakehouse—whether from the same workspace or an external one. However, we have a scenario that requires multiple lakehouses in one notebook:
Platform workspace holds our base shortcut tables.
Reporting workspace hosts notebooks that consume those shortcuts and persist transformed output.
In each notebook, we must attach:
The Reporting workspace lakehouse (for writing results)
One or more Platform workspace lakehouses (as input sources)
Because Fabric notebooks only support a single configuration cell, we currently rely on a post-deployment automation script to rebind the additional lakehouses for UAT/Prod. This extra step is manual and adds complexity.
Question: Is there a recommended workaround or best practice for attaching multiple lakehouses—across the same or different workspaces—directly within a Fabric notebook, without triggering a Spark session restart?
Any insights or suggestions would be greatly appreciated. Thank you!