RMO error after upgrading SQL server from 2019 to 2022

Wu, Clarissa 0 Reputation points
2024-09-10T22:09:43.6566667+00:00

This script works ok until SQL upgrade from SQL 2019 to SQL2022. I use it to get scripts of replication settings.

Command:

New-Object "Microsoft.SqlServer.Replication.ReplicationServer" $sqlserver

Error:

Could not load file or assembly 'Microsoft.SqlServer.ConnectionInfo, Version=17.100.0.0, Culture=neutral,

PublicKeyToken=89845dcd8080cc91' or one of its dependencies. The system cannot find the file specified.

At line:1 char:1

  • New-Object "Microsoft.SqlServer.Replication.ReplicationServer" $sqlse ...
  • 
        + CategoryInfo          : NotSpecified: (:) [New-Object], FileNotFoundException
    
        + FullyQualifiedErrorId : System.IO.FileNotFoundException,Microsoft.PowerShell.Commands.NewObjectCommand
    
SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
13,865 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Hardikbhai Velani 75 Reputation points
    2024-09-24T08:17:08.56+00:00

    The issue you're experiencing is likely due to the SQL Server upgrade from 2019 to 2022, which changed the version of the Microsoft.SqlServer.ConnectionInfo assembly.

    To resolve this:

    Option 1: Install SQL Server 2022 Management Studio

    Installing SQL Server 2022 Management Studio will update the assemblies to the latest version.

    Option 2: Update SQL Server PowerShell Module

    Update the SQL Server PowerShell module to the latest version using:

    
    Install-Module -Name SqlServer -Force
    
    

    Option 3: Assembly Redirect

    Create a configuration file (ReplicationServer.exe.config) in the same directory as your script with the following content:

    
    <?xml version="1.0"?>
    
    <configuration>
    
      <runtime>
    
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
    
          <dependentAssembly>
    
            <assemblyIdentity name="Microsoft.SqlServer.ConnectionInfo" publicKeyToken="89845dcd8080cc91" culture="neutral"/>
    
            <bindingRedirect oldVersion="17.100.0.0" newVersion="18.100.0.0"/>
    
          </dependentAssembly>
    
        </assemblyBinding>
    
      </runtime>
    
    </configuration>
    
    

    Option 4: Use SQL Server 2022-specific assemblies

    Download and install the Microsoft.SqlServer.Replication.dll and Microsoft.SqlServer.ConnectionInfo.dll assemblies for SQL Server 2022.

    Verify the assembly versions:

    
    [System.Reflection.Assembly]::LoadFrom("C:\Path\To\Microsoft.SqlServer.ConnectionInfo.dll").GetName().Version
    
    

    Adjust your script to use the updated assemblies:

    
    Add-Type -Path "C:\Path\To\Microsoft.SqlServer.Replication.dll"
    
    Add-Type -Path "C:\Path\To\Microsoft.SqlServer.ConnectionInfo.dll"
    
    New-Object "Microsoft.SqlServer.Replication.ReplicationServer" $sqlserver
    
    

    If none of these options work, provide more details about your environment and script for further assistance.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.