11
votes

I am using:

using Microsoft.SqlServer.Management.Smo;
using Microsoft.SqlServer.Management.Common;

I am using the above namespaces for restore database from c# window form, but the compiler tell me

The type or namespace name 'Management' does not exist in the namespace 'MicrosoftSqlServer' are you missing an assembly reference

And I follow some advice from Google, found the DLL in C:\Program Files\Microsoft SQL Server\100\SDK\Assemblies:

Microsoft.SqlServer.Smo.dll;
Microsoft.SqlServer.ConnectionInfo.dll

and I copy them and paste them to all the location in my project, but I still have error message from compiler.

Could anyone where I can put the reference to?

4
Add references to the needed assemblies - Robert Harvey

4 Answers

11
votes

I "fixed" this by reinstalling SqlServer Scripting through the Nuget console:

>> Uninstall-Package Microsoft.SqlServer.Scripting

>> Install-Package Microsoft.SqlServer.Scripting
2
votes

Dont manually copy the SQL Management DLLs to the project folder.

In Visual Studio, in the Project in Solution Explorer, right click References > Add.

1
votes

Install SMO from MS-issued NuGet Package

The SQL Server Management Objects (SMO) Framework is a set of objects designed for programmatic management of Microsoft SQL Server and Microsoft Azure SQL Database.

Beginning with SQL Server 2017 SMO is distributed as the Microsoft.SqlServer.SqlManagementObjects NuGet package to allow users to develop applications with SMO. This means it's no longer necessary to install the Microsoft SQL Server SDK as a separate install.

To install SMO as a NuGet Package:

  1. First, open that Package Manager Console. In Visual Studio: ToolsNuGet Package ManagerPackage Manager Console

  2. Use the console to install the Microsoft.SqlServer.SqlManagementObjects NuGet package:

    Install-Package Microsoft.SqlServer.SqlManagementObjects

Now, the SMO references are available as package references (Expand References for the given project):

Project SMO refefences

0
votes

Rather than using any workarounds, I found the root cause of my issue: I had a bad download of the SQL Server ISO. I confirmed that by double-checking SHA1 hash (74279286C2ABFBA9E9FF6DBEE60B71669BD234D2) of the downloaded file.

After re-downloading and re-installing, my project worked as expected.

Extra info: Finding Checksum Values in Windows 10

I used PowerShell:

Get-FileHash -Path .\en_sql_server_2016_developer_with_service_pack_2_x64_dvd_12194995.iso -Algorithm SHA1