<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Unable to read from Mirrored Database via synapsesql — 'Failed to lookup datamart by name' in Data Engineering</title>
    <link>https://community.fabric.microsoft.com/t5/Data-Engineering/Unable-to-read-from-Mirrored-Database-via-synapsesql-Failed-to/m-p/5159996#M16052</link>
    <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hi community,&lt;/P&gt;&lt;P&gt;I'm running into an issue reading from a Mirrored Azure SQL Database using the `synapsesql` connector in a Fabric Notebook (Runtime 1.3, Spark 3.5.1). I've added both the Mirrored Database item **and** its auto-created SQL Analytics Endpoint as data sources in the notebook Explorer panel, but the read still fails.&lt;/P&gt;&lt;P&gt;---&lt;/P&gt;&lt;P&gt;**Environment**&lt;BR /&gt;- Fabric Runtime: 1.3 (Spark 3.5, Delta 3.2)&lt;BR /&gt;- Notebook language: PySpark (Python)&lt;BR /&gt;- Source item: Mirrored Azure SQL Database (display name: `wideworldimporters`)&lt;BR /&gt;- Both the MirroredDatabase item and its SQLEndpoint are added as data sources in the notebook&lt;/P&gt;&lt;P&gt;---&lt;/P&gt;&lt;P&gt;**Code**&lt;/P&gt;&lt;P&gt;```python&lt;BR /&gt;import com.microsoft.spark.fabric&lt;/P&gt;&lt;P&gt;mirror_db_name = 'wideworldimporters'&lt;/P&gt;&lt;P&gt;customers_df = spark.read.synapsesql(f'{mirror_db_name}.Sales.Customers')&lt;BR /&gt;```&lt;/P&gt;&lt;P&gt;---&lt;/P&gt;&lt;P&gt;**Error**&lt;/P&gt;&lt;P&gt;```&lt;BR /&gt;Py4JJavaError: An error occurred while calling o5276.synapsesql.&lt;BR /&gt;: com.microsoft.spark.fabric.tds.error.FabricSparkTDSInternalError:&lt;BR /&gt;Failed to lookup datamart by name wideworldimporters&lt;BR /&gt;at com.microsoft.spark.fabric.tds.meta.FabricTDSEndPoint$&lt;BR /&gt;.lookupDataMartFromWorkspaceItems(FabricTDSEndPoint.scala:609)&lt;BR /&gt;```&lt;/P&gt;&lt;P&gt;---&lt;/P&gt;&lt;P&gt;**What I've found so far**&lt;/P&gt;&lt;P&gt;When I run `fabric.list_items()` via sempy, I can see that Fabric has created **two items** with the display name `wideworldimporters` in the same workspace:&lt;/P&gt;&lt;P&gt;| Id | Display Name | Type |&lt;BR /&gt;|---|---|---|&lt;BR /&gt;| 05560d20-... | wideworldimporters | **SQLEndpoint** |&lt;BR /&gt;| 5f49d0ff-... | wideworldimporters | **MirroredDatabase** |&lt;/P&gt;&lt;P&gt;It appears the `synapsesql` reader is resolving by display name, picking the `SQLEndpoint` item instead of the `MirroredDatabase`, and failing with a 404. This is the auto-generated SQL Analytics Endpoint that Fabric creates alongside the Mirror — it shares the exact same display name.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 28 Apr 2026 12:23:27 GMT</pubDate>
    <dc:creator>praveensreeram</dc:creator>
    <dc:date>2026-04-28T12:23:27Z</dc:date>
    <item>
      <title>Unable to read from Mirrored Database via synapsesql — 'Failed to lookup datamart by name'</title>
      <link>https://community.fabric.microsoft.com/t5/Data-Engineering/Unable-to-read-from-Mirrored-Database-via-synapsesql-Failed-to/m-p/5159996#M16052</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hi community,&lt;/P&gt;&lt;P&gt;I'm running into an issue reading from a Mirrored Azure SQL Database using the `synapsesql` connector in a Fabric Notebook (Runtime 1.3, Spark 3.5.1). I've added both the Mirrored Database item **and** its auto-created SQL Analytics Endpoint as data sources in the notebook Explorer panel, but the read still fails.&lt;/P&gt;&lt;P&gt;---&lt;/P&gt;&lt;P&gt;**Environment**&lt;BR /&gt;- Fabric Runtime: 1.3 (Spark 3.5, Delta 3.2)&lt;BR /&gt;- Notebook language: PySpark (Python)&lt;BR /&gt;- Source item: Mirrored Azure SQL Database (display name: `wideworldimporters`)&lt;BR /&gt;- Both the MirroredDatabase item and its SQLEndpoint are added as data sources in the notebook&lt;/P&gt;&lt;P&gt;---&lt;/P&gt;&lt;P&gt;**Code**&lt;/P&gt;&lt;P&gt;```python&lt;BR /&gt;import com.microsoft.spark.fabric&lt;/P&gt;&lt;P&gt;mirror_db_name = 'wideworldimporters'&lt;/P&gt;&lt;P&gt;customers_df = spark.read.synapsesql(f'{mirror_db_name}.Sales.Customers')&lt;BR /&gt;```&lt;/P&gt;&lt;P&gt;---&lt;/P&gt;&lt;P&gt;**Error**&lt;/P&gt;&lt;P&gt;```&lt;BR /&gt;Py4JJavaError: An error occurred while calling o5276.synapsesql.&lt;BR /&gt;: com.microsoft.spark.fabric.tds.error.FabricSparkTDSInternalError:&lt;BR /&gt;Failed to lookup datamart by name wideworldimporters&lt;BR /&gt;at com.microsoft.spark.fabric.tds.meta.FabricTDSEndPoint$&lt;BR /&gt;.lookupDataMartFromWorkspaceItems(FabricTDSEndPoint.scala:609)&lt;BR /&gt;```&lt;/P&gt;&lt;P&gt;---&lt;/P&gt;&lt;P&gt;**What I've found so far**&lt;/P&gt;&lt;P&gt;When I run `fabric.list_items()` via sempy, I can see that Fabric has created **two items** with the display name `wideworldimporters` in the same workspace:&lt;/P&gt;&lt;P&gt;| Id | Display Name | Type |&lt;BR /&gt;|---|---|---|&lt;BR /&gt;| 05560d20-... | wideworldimporters | **SQLEndpoint** |&lt;BR /&gt;| 5f49d0ff-... | wideworldimporters | **MirroredDatabase** |&lt;/P&gt;&lt;P&gt;It appears the `synapsesql` reader is resolving by display name, picking the `SQLEndpoint` item instead of the `MirroredDatabase`, and failing with a 404. This is the auto-generated SQL Analytics Endpoint that Fabric creates alongside the Mirror — it shares the exact same display name.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 28 Apr 2026 12:23:27 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Data-Engineering/Unable-to-read-from-Mirrored-Database-via-synapsesql-Failed-to/m-p/5159996#M16052</guid>
      <dc:creator>praveensreeram</dc:creator>
      <dc:date>2026-04-28T12:23:27Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to read from Mirrored Database via synapsesql — 'Failed to lookup datamart by name'</title>
      <link>https://community.fabric.microsoft.com/t5/Data-Engineering/Unable-to-read-from-Mirrored-Database-via-synapsesql-Failed-to/m-p/5160220#M16053</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/1560298"&gt;@praveensreeram&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The synapsesql connector is designed to work only with a Warehouse or a SQL analytics endpoint of a lakehouse; it does not work with Mirrored database items.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;"The Spark connector for Fabric Data Warehouse enables Spark developers and data scientists to access and work with data from&amp;nbsp;&lt;A href="https://learn.microsoft.com/en-us/fabric/data-warehouse/data-warehousing#data-warehousing-items" target="_blank" rel="noopener"&gt;a warehouse and the SQL analytics endpoint of a lakehouse&lt;/A&gt;."&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://learn.microsoft.com/en-us/fabric/data-engineering/spark-data-warehouse-connector?tabs=pyspark" target="_blank" rel="noopener"&gt;Spark connector for Microsoft Fabric Data Warehouse - Microsoft Fabric | Microsoft Learn&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You can use SparkSQL to read a mirrored database item using a Notebook as described here in this Microsoft doc.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://learn.microsoft.com/en-us/fabric/mirroring/explore-onelake-shortcut" target="_blank" rel="noopener"&gt;Explore Data in Your Mirrored Database With Notebooks - Microsoft Fabric | Microsoft Learn&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 28 Apr 2026 16:40:52 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Data-Engineering/Unable-to-read-from-Mirrored-Database-via-synapsesql-Failed-to/m-p/5160220#M16053</guid>
      <dc:creator>deborshi_nag</dc:creator>
      <dc:date>2026-04-28T16:40:52Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to read from Mirrored Database via synapsesql — 'Failed to lookup datamart by name'</title>
      <link>https://community.fabric.microsoft.com/t5/Data-Engineering/Unable-to-read-from-Mirrored-Database-via-synapsesql-Failed-to/m-p/5160252#M16056</link>
      <description>&lt;P&gt;For those who have similar situation like me and don't want to use SparkSQL here is how i was able to read the data from Mirrored SQL database using Onelake path itself and store the data into the warehouse table&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="php"&gt;# nb_load_dim_customer
# Loads dim_customer. Joins Customers to dim_city for city_key lookup.
# DEPENDENCY: nb_load_dim_city must have run first.
# Requires: Runtime 1.3+, wh_wwi attached to notebook.

from pyspark.sql.functions import col, monotonically_increasing_id
import com.microsoft.spark.fabric



# ---------------------------------------------------------------------------
# 1. Read Customers from Mirror via OneLake Delta path
# ---------------------------------------------------------------------------
base = f'abfss://{workspace_id}@onelake.dfs.fabric.microsoft.com/{mirror_item_id}/Tables'
customers_df = spark.read.format('delta').load(f'{base}/Sales/Customers')

# Read dim_city back from the Warehouse via synapsesql (no name collision here)
dim_city_ref = spark.read.synapsesql(f'{warehouse_name}.dbo.dim_city').select('city_key', 'city_id')

# ---------------------------------------------------------------------------
# 2. Join and select
#    customer_key: BIGINT generated by monotonically_increasing_id()
#    city_key FK: BIGINT to match dim_city.city_key
# ---------------------------------------------------------------------------
dim_customer_df = (
    customers_df.alias('cu')
    .join(dim_city_ref.alias('dc'), col('cu.DeliveryCityID') == col('dc.city_id'))
    .select(
        monotonically_increasing_id().alias('customer_key'),
        col('cu.CustomerID').alias('customer_id'),
        col('cu.CustomerName').alias('customer_name'),
        col('dc.city_key'),
        col('cu.AccountOpenedDate').alias('account_opened'),
        col('cu.IsOnCreditHold').alias('is_on_credit_hold')
    )
)

dim_customer_df.write.mode('overwrite').synapsesql(f'{warehouse_name}.dbo.dim_customer')
print(f'dim_customer loaded: {dim_customer_df.count():,} rows')&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 28 Apr 2026 17:28:21 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Data-Engineering/Unable-to-read-from-Mirrored-Database-via-synapsesql-Failed-to/m-p/5160252#M16056</guid>
      <dc:creator>praveensreeram</dc:creator>
      <dc:date>2026-04-28T17:28:21Z</dc:date>
    </item>
  </channel>
</rss>

