Bobcares

Cannot find type microsoft.sqlserver.management.smo.relocatefile

by | Jun 18, 2022

Cannot find type microsoft.sqlserver.management.smo.relocatefile error troubleshooting tips by our experts will resolve the issue in no time, 

At Bobcares, we offer solutions for every query, big and small, as a part of our SQL Server Support Services.

Let’s take a look at how our Support Team is ready to introduce customers to different ways of resolving “Cannot find type microsoft.sqlserver.management.smo.relocatefile” error.

Resolved: Cannot find type microsoft.sqlserver.management.smo.relocatefile

Have you been running into issues with the RelocacteFile property recently? It often causes errors like these to pop up:

Restore-SqlDatabase : Cannot bind parameter 'RelocateFile'. Cannot convert the 
"Microsoft.SqlServer.Management.Smo.RelocateFile" value of type 
"Microsoft.SqlServer.Management.Smo.RelocateFile" to type 
"Microsoft.SqlServer.Management.Smo.RelocateFile".
At line:43 char:104

Cannot find type microsoft.sqlserver.management.smo.relocatefile

 

Fortunately, our Support Techs have come up with a couple of troubleshooting tips to resolve the issue:

  • To begin with, ensure that the SMO version corresponds to what Restore-SqlDatabase expects.
  • Another troubleshooting option involves using Microsoft.SqlServer.Management.Smo.Restore.SqlRestore method rather than Restore-SqlDatabase cmdlet.
  • Alternatively, try specifying the qualified name as we instantiate relocate file in order to use the correct assembly:
    $RelocateData = New-Object 'Microsoft.SqlServer.Management.Smo.RelocateFile, Microsoft.SqlServer.SmoExtended, Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91' -ArgumentList "MyDB_Data", "c:\data\MySQLServerMyDB.mdf"
    $RelocateLog = New-Object 'Microsoft.SqlServer.Management.Smo.RelocateFile, Microsoft.SqlServer.SmoExtended, Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91' -ArgumentList "MyDB_Log", "c:\data\MySQLServerMyDB.ldf"
    $file = New-Object Microsoft.SqlServer.Management.Smo.RelocateFile($RelocateData,$RelocateLog) 
    $myarr=@($RelocateData,$RelocateLog)
    Restore-SqlDatabase -ServerInstance DEV\DEMO -Database "test" -BackupFile $backupfile -RelocateFile $myarr

If the options did not resolve the error, fear not, our Support Team has one more method that will help you out. Before we being, it is important to understand the root cause. In most scenarios, two versions of SQLPS module are present in the system after an upgrade. We can verify this with Get-Module -ListAvailable.

Additionally, when we run the Import-Module SQLPS command, it loads both the SQLPS module versions.

# Get loaded assemblies
([appdomain]::CurrentDomain.GetAssemblies() | where {$_.FullName -like "*smo*"}).Location

This results in the cmdlets like Backup-SQL database getting bound to SQL 2012 version. However, if we create a new SMO object, it binds to the SQL Server 2014 version.

According to our Support Techs, we can ensure this does not occur by using one of the assemblies. In other words, either SQL Server 2014 or SQL Server 2012.

In this scenario, we will modify the environment variable $env:PSModulePath.

For instance:

$TempArray = @()
$TempArray = $env:PSModulePath -split ';'
# 110 for SQL 2012, 120 for SQL 2014, 130 for SQL 2016
$env:PSModulePath = ($TempArray -notmatch '110') -join ';'

Let us know in the comments which troubleshooting tip helped resolve the “Cannot find type microsoft.sqlserver.management.smo.relocatefile” error.

[Need assistance with a different issue? We are available 24/7.]

Conclusion

In a nutshell, our skilled SQL Server Support Engineers at Bobcares put together different ways to resolve the “Cannot find type microsoft.sqlserver.management.smo.relocatefile” error.

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

GET STARTED

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Never again lose customers to poor
server speed! Let us help you.