Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
keataunooi
Regular Visitor

How to set default Lakehouse in the notebook programmatically?

Hi All,

 

Here are my workspace setup:

 

WorkspaceFabric's ArtifactsGit branch folder
Fabric-Sandbox

notebook: landingtoBronze

lakehouse: Bronze

feature/bronze123

Fabric-Dev

notebook: landingtoBronze

lakehouse: Bronze

Dev

 

Problem:

 

Each time i updated the notebooks code to the Fabric-Dev workspace , i need to attach bronze lakehouse to "landingtoBronze" notebooks manually in the workspace so that it point to the right bronze lakehouse.  

Please note that each workspace has it own Bronze Lakehouse.

 

For example, I was working in the "landingtoBronze" notebook in my feature branch in the Fabric-sandbox workspace. during the notebook development, I attached the bronze lakehouse of the workspace as default lakehouse to the notebook.

once i had finished my notebook development, i created the pull request and merge the code from feature branch into dev branch.

 

while getting the code updated in the Fabric-Dev workspace, I can see the default bronze database is actually referring to the Fabric Sandbox workspace. 

 

Is it possible to attach a default lakehouse in the notebook programmactically?

 

Looking forward to hearing for any suggestion. it could be something that i am doing wrongly.

 

keataunooi_1-1709176759934.png

 

 Thanks.

1 ACCEPTED SOLUTION
Anonymous
Not applicable

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.

View solution in original post

10 REPLIES 10
gori137
Regular Visitor

Thanks for an excelent question. I can't use the %%configure command.
The error message is :
UsageError: Line magic function '%%configure' not found.

Same for me. Is there missing a library? Isn't this magic part of sparkmagic? When use %pip install to install sparkmagic, an error is occurring "ERROR: Could not build wheels for gssapi, krb5, which is required to install pyproject.toml-based projects"...

felipe_regis
New Member

For some people it worked but It didn't work for me. I got "UsageError: Line magic function `%%configure` not found."

Why?

Thanks

 

 

Anonymous
Not applicable

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.

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:

    1. The Reporting workspace lakehouse (for writing results)

    2. 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!

But is that I have to have this cell at first in the notebook?

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 ?

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 ?

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 

Create deployment rules for Fabric's Application lifecycle management (ALM) - Microsoft Fabric | Mic...

 

Thanks again!

 

Anonymous
Not applicable

Hi @keataunooi 
Glad that your query got resolved. Please continue using Fabric Community for any help regarding your queries.

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June FBC25 Carousel

Fabric Monthly Update - June 2025

Check out the June 2025 Fabric update to learn about new features.