1

The type or namespace name 'Server' could not be found (are you missing a using directive or an assembly reference?)

string connetionString = @"connectionStirng"; 
SqlConnection conn = new SqlConnection(connetionString); 
var server = new Server(new ServerConnection(conn));

added at the top

using Microsoft.SqlServer.Management.Common;

Still giving error.
Any help appricated.

Already checked:
Why i'm getting error for the Microsoft.SqlServer.Server namespace?
I can't add Microsoft.SqlServer.Management.Common to my ASP.NET MVC Application

enter image description here

12
  • Have you checked the References in your project? Commented Oct 11, 2018 at 9:07
  • 1
    "are you missing a using directive or an assembly reference?" - You added the using, but did you also add the assembly reference? Commented Oct 11, 2018 at 9:07
  • @Han: yes it is thr Commented Oct 11, 2018 at 9:16
  • 1
    Make sure that C:\Program Files (x86)\Microsoft SQL Server\140\SDK\Assemblies\Microsoft.SqlServer.ConnectionInfo.dll is in the references of your project. The folder might different if you use different SQL Server. Mine is SQL Express bundled in VS 2017. Commented Oct 11, 2018 at 9:24
  • 1
    Those seem to be using the SMO objects from the Microsoft.SqlServer.Management.Smo namespace, E.g. Server Commented Oct 11, 2018 at 9:50

3 Answers 3

1

Install this nuget package:

https://www.nuget.org/packages/Microsoft.SqlServer.SqlManagementObjects

Then add using directive:

using Microsoft.SqlServer.Management.Smo;

Now you can create Server object.

var server = new Server();

Installing SMO

Beginning with SQL Server 2017 SMO is distributed as the Microsoft.SqlServer.SqlManagementObjects NuGet package to allow users to develop applications with SMO.

This is a replacement for SharedManagementObjects.msi, which was previously released as part of the SQL Feature Pack for each release of SQL Server. Applications that use SMO should be updated to use the NuGet package instead and will be responsible for ensuring the binaries are installed with the application being developed.

https://learn.microsoft.com/en-us/sql/relational-databases/server-management-objects-smo/installing-smo?view=sql-server-2017

Sign up to request clarification or add additional context in comments.

7 Comments

It is already added to references and exists in folder you specified. still getting error
cant install that because of NuGet version required 2.12 but i can update NuGet because of VS 2012. see stackoverflow.com/questions/27384885/…
@SureshKamrushi I saw your screenshot. You wrote new server(...). It should be new Server(...). C# is case sensitive.
using directive, not using statement. C# has two features that both use the using keyword. Using the name of one to refer to the other doesn't aid communication.
It solved because of installation of "Microsoft.SqlServer.SqlManagementObjects". typo is because i trying it with different cases.
|
0

As suggested by Han, Please check the assembly reference path and make sure that the file is there at the referenced location. I had faced similar problem, this was working on the Development environment but error on test server. The reason was the SQL Server Management studio was not installed on the Test server. So i copied the required Assemblies from dev machine to bin folder of the application on test server and that worked.

Comments

0

Can you try adding a reference to:

Microsoft.SqlServer.dac.dll

If cant find the dll, then need to install SSDT (Sql Server Data Tools).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.