Tuesday, May 15, 2012

Could not load file or assembly 'Microsoft.SqlServer.Smo, Version=, ...

I have recently experienced an issue which had to do with a third-party application that was trying to retrieve some meta information from a specific SQL Server Instance. It was actually trying to retrieve the names of all the databases contained within that instance.

However it was returning the following error message (app code excluded):
[.......] Received the following from the MS SQL server: Could not load file or assembly 'Microsoft.SqlServer.Smo, Version=, Culture=neutral, PublicKeyToken=89845dcd8080cc91' or one of its dependencies. The system cannot find the file specified.

SMO stands for Shared Management Objects and it is basically an API that can be used by third-party applications for programmatically managing all aspects of SQL Server.

As the above message was quite explanatory, I directly checked the Global Assembly Cache (GAC) under "c:\windows\assembly" to see if the assembly (DLL) was listed there. Guess what? It was not!

In such cases you have two options:
1. Run the installer that registers the missing assemblies to the GAC, or
2. Use Gacutil.exe to manually register the assembly after you get the relevant dll.

As I did not have much time, I prefered downloading and running the SMO installer :)

From the error description, version of SMO is the SQL Server 2008 version so I just had to download the proper package and install it.

The package can be found in Microsoft SQL Server 2008 R2 Shared Management Objects. You can download it here.

After visiting the above link, look for "Microsoft SQL Server 2008 R2 Shared Management Objects". The available packages are the following:
- X86 Package (SharedManagementObjects.msi)
- X64 Package (SharedManagementObjects.msi)
- IA64 Package (SharedManagementObjects.msi)

I downloaded and installed the proper package, verified that the assembly was registered in GAC, and tried again! The application worked, successfully listing the names of the databases in the instance!

Hope this helps!

My Latest Projects:

Check out my latest eBooks on SQL Server:
Administering SQL Server - Ebook Tuning SQL Server - Ebook

Easily secure your SQL Server instances! Try out DBA Security Advisor!
DBA Security Advisor for SQL Server by SQLArtBits
DBA Security Advisor was developed by SQLArtBits. The tool was being carefully developed for an entire year and it contains comprehensive security checks and recommendations based on proven SQL Server security best practices. Feel free to download and use the Community Edition which is free and if you find it useful, you can consider upgrading to the Enterprise Edition!

Artemakis Artemiou [MVP]

Author & Editor

Artemakis Artemiou is a Senior SQL Server Architect, Software Developer and Microsoft Data Platform MVP. He is also an author, regular blogger, president of Cyprus.NET User Group and CY Country leader of INETA-EU. He is also the creator of DBA Security Advisor and In-Memory OLTP Simulator. Artemakis is a frequent guest author of worldwide well-respected online journals where he writes articles focusing on many SQL Server topics.

Reference: The SQL Server and .NET Hub (http://www.sqlnethub.com)


jovton said...

Hi. The download link doesn't work anymore, because Microsoft has moved the link. But here are the working links for the x86 (32bit) and x64 (64 bit) version respectively...


Artemakis Artemiou [MVP] said...

Link updated in original article!

Thank you for your comment!

Please note that in your comment, the 32-bit link you posted points to PowerShellTools and the 64-bit link points to the 32-bit of Shared Management Objects. Perhaps a little link copy-paste mistake? :)