I'm glad that you were able to resolve your issue and thank you for posting your solution so that others experiencing the same thing can easily reference this!
Since the Microsoft Q&A community has a policy that "The question author cannot accept their own answer. They can only accept answers by others ", I'll repost your solution in case you'd like to "Accept " the answer. Accepted answers show up at the top, resulting in improved discoverability for others.
Issue: Issue with creating a link between SQL Server and Azure SQL Managed Instance due to an internal server error
Solution:
- Creating Availability Groups (AG) and Distributed Availability Groups (DAG):
- Manually create the AG on the primary SQL server using a script:
CREATE AVAILABILITY GROUP [AG_] WITH (CLUSTER_TYPE = NONE) FOR DATABASE [] REPLICA ON N'' WITH (ENDPOINT_URL = N'tcp://:5022', FAILOVER_MODE = MANUAL, AVAILABILITY_MODE = SYNCHRONOUS_COMMIT, SEEDING_MODE = AUTOMATIC);
- Manually create the AG on the primary SQL server using a script:
GO ```
- Create the DAG on the primary SQL server:
CREATE AVAILABILITY GROUP [DAG_] WITH (DISTRIBUTED) AVAILABILITY GROUP ON N'AG_' WITH (LISTENER_URL = N'tcp://:5022', AVAILABILITY_MODE = ASYNCHRONOUS_COMMIT, FAILOVER_MODE = MANUAL, SEEDING_MODE = AUTOMATIC), N'AG__MI' WITH (LISTENER_URL = N'tcp://:5022;Server=[]', AVAILABILITY_MODE = ASYNCHRONOUS_COMMIT, FAILOVER_MODE = MANUAL, SEEDING_MODE = AUTOMATIC);
GO ```
- Upgrading Azure Console PowerShell:
- Upgrade to the latest version of Azure PowerShell (version 13):
Install-Package -Name Az -force
- Upgrade to the latest version of Azure PowerShell (version 13):
- Executing Azure Console PowerShell Script:
- Use the
New-AzSqlInstanceLink
command to create the link:New-AzSqlInstanceLink -ResourceGroupName "" -InstanceName -Name $DAGName -Database -InstanceAvailabilityGroupName -PartnerAvailabilityGroupName -InstanceLinkRole "Secondary" -PartnerEndpoint $SourceIP -FailoverMode "Manual" -SeedingMode "Automatic"
- Use the
This approach successfully seeded the primary database to the managed instance secondary and started the replication process.