Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c#

.net

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?

like image 510
Kam2012 Avatar asked Jan 08 '13 03:01

Kam2012


1 Answers

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

like image 197
CJBS Avatar answered Oct 16 '22 19:10

CJBS