Forum Discussion

andyparkerson's avatar
andyparkerson
Advocate III
3 months ago
Solved

Change Source Connection on Mirrored Database

Is there any way to change the connection that an existing Mirrored Database is using?

 

We are migrating to a new gateway (someone forgot to write down the Recovery Key) and we want everything to go through the new gateway. The only way we can make that happen is to create new connections, and use those everywhere. Pipelines and notebooks are fine, but I can't figure out how to change the connection that a mirrored database uses.

 

Is this possible? Or do I need to recreate the mirrored database again?

 

Thanks!

  • Hi andyparkerson,

    Hope you're doing well!

     

    There is no option in the Fabric portal to swap the connection on an existing Mirrored Database. The connection is set at creation time and the UI does not expose a way to change it directly.

     

    Solution :

     

    The Fabric Mirroring Public REST API supports updating a mirrored database's definition, including the connection property in the source configuration.  https://learn.microsoft.com/en-us/fabric/mirroring/mirrored-database-rest-api

     

    So, you can do this without recreating the item by doing it step by step:

     

    • Call GET https://api.fabric.microsoft.com/v1/workspaces/<workspaceId>/mirroredDatabases/<mirroredDatabaseId>/getDefinition to retrieve the current definition.
    • In the returned JSON, locate the source.typeProperties.connection field and replace the old connection ID with your new one.
    • Call POST .../updateDefinition with the modified payload.

    The definition structure (JSON) looks like this:

    {

      "properties": {

        "source": {

          "type": "<your source type>",

          "typeProperties": {

            "connection": "<NEW-CONNECTION-ID>",

            "database": "your-db-name"

          }

        }

      }

    }

     

    You can find your new connection ID by going to: Settings → Manage connections and gateways → [your connection] → Settings → Connection ID.

     

    Hope this helps! Feel free to tell us if that works. Don't forget to mark as solution and thumbs up, that's motivate me to keep helping 🙂

     

    Best regards,

    Oussama (Data Consultant - Expert Fabric & Power BI)

  • Hey andyparkerson,

    Agree with oussamahaimoud on the REST API approach. But there's an important prerequisite: the Connection ID (and database name) can only be updated when mirroring status is Initialized or Stopped.

    Before calling updateDefinition API directly:

    1. Stop mirroring via the portal or Stop Mirroring API.
    2. Confirm status via getMirroringStatus.
    3. Call updateDefinition with the new connection ID.
    4. Restart mirroring.

    Heads up on restart: After swapping the connection, expect a full re-initialization. Existing data in OneLake is preserved, but every table will be fetched from scratch. So, plan your re-sync window accordingly.

    Useful link: Fabric Mirroring Public REST API - Microsoft Fabric | Microsoft Learn

    Please do share if it works without stopping mirroring first, or any useful findings.

    Hope this helps!

    Best,

    Harshit

5 Replies

  • Hi andyparkerson,

    Hope you're doing well!

     

    There is no option in the Fabric portal to swap the connection on an existing Mirrored Database. The connection is set at creation time and the UI does not expose a way to change it directly.

     

    Solution :

     

    The Fabric Mirroring Public REST API supports updating a mirrored database's definition, including the connection property in the source configuration.  https://learn.microsoft.com/en-us/fabric/mirroring/mirrored-database-rest-api

     

    So, you can do this without recreating the item by doing it step by step:

     

    • Call GET https://api.fabric.microsoft.com/v1/workspaces/<workspaceId>/mirroredDatabases/<mirroredDatabaseId>/getDefinition to retrieve the current definition.
    • In the returned JSON, locate the source.typeProperties.connection field and replace the old connection ID with your new one.
    • Call POST .../updateDefinition with the modified payload.

    The definition structure (JSON) looks like this:

    {

      "properties": {

        "source": {

          "type": "<your source type>",

          "typeProperties": {

            "connection": "<NEW-CONNECTION-ID>",

            "database": "your-db-name"

          }

        }

      }

    }

     

    You can find your new connection ID by going to: Settings → Manage connections and gateways → [your connection] → Settings → Connection ID.

     

    Hope this helps! Feel free to tell us if that works. Don't forget to mark as solution and thumbs up, that's motivate me to keep helping 🙂

     

    Best regards,

    Oussama (Data Consultant - Expert Fabric & Power BI)

    • andyparkerson's avatar
      andyparkerson
      Advocate III

      Oussama,

       

      Thanks for your help. I opened a ticket with MS about this, but they came back and said it wasn't supported. I guess they meant through the UI. The REST APIs are so powerful. I'll have to keep that in mind going forward.

       

      One small hiccup I ran into was that the definition payload in the Update Mirrored Database Definition API call was not just the base64 encoded definition, but the JSON wrapper as well.

       

      { 
        "definition": { 
          "parts": [ 
            { 
              "path": "mirroring.json", 
              "payload": "eyAicHJvcGVydGllcy..WJsZSIgfSB9IH0gXSB9IH0", 
              "payloadType": "InlineBase64" 
            } 
          ] 
        } 
      }

       

      I got a 400 when I just had 

      { 
        "definition": "eyAicHJvcGVydGllcy..WJsZSIgfSB9IH0gXSB9IH0" // WRONG!!!
      }

       

      Thanks again! I was able to stop replication (thanks Hashit!), update my mirrored database to use the new connection, and restart replication again.

       

      Cheers,

      Andy

  • Hey andyparkerson,

    Agree with oussamahaimoud on the REST API approach. But there's an important prerequisite: the Connection ID (and database name) can only be updated when mirroring status is Initialized or Stopped.

    Before calling updateDefinition API directly:

    1. Stop mirroring via the portal or Stop Mirroring API.
    2. Confirm status via getMirroringStatus.
    3. Call updateDefinition with the new connection ID.
    4. Restart mirroring.

    Heads up on restart: After swapping the connection, expect a full re-initialization. Existing data in OneLake is preserved, but every table will be fetched from scratch. So, plan your re-sync window accordingly.

    Useful link: Fabric Mirroring Public REST API - Microsoft Fabric | Microsoft Learn

    Please do share if it works without stopping mirroring first, or any useful findings.

    Hope this helps!

    Best,

    Harshit

    • andyparkerson's avatar
      andyparkerson
      Advocate III

      Harshit,

       

      Thanks so much for this heads up. I definitely would have tried to update without stopping first.

       

      It is important to know that when you stop the replication, restarting it pulls down a complete copy of the tables. So people should bare that in mind when scheduling the restart.

       

      Thanks again,

      Andy