C# SMO and SqlEnum references error
Asked Answered
C

1

3

I am doing a C# project by VS2013 which is using smo object. I installed

Install-Package Microsoft.SqlServer.Scripting
Install-Package Microsoft.SqlServer.SqlEnum.dll

by Nuget

and included

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

but getting the following error

Error 9 Assembly 'Microsoft.SqlServer.Smo, Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91' uses 'Microsoft.SqlServer.SqlEnum, Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91' which has a higher version than referenced assembly 'Microsoft.SqlServer.SqlEnum, Version=10.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91'

any hand?

Catchpenny answered 25/4, 2016 at 5:54 Comment(0)
S
8

The problem is version mismatch between Smo and SqlEnum component, as the exception specifies. The problem is that the package, you have used Install-Package Microsoft.SqlServer.SqlEnum.dll is an older package for SQL Server 2008.

There are folders containing the neccessary DLL files (Microsoft.SqlServer.SqlEnum.dll, Microsoft.SqlServer.ConnectionInfo.dll, Microsoft.SqlServer.Smo.dll) in your SQL Server installation folder:

  • SQL Server 2012 C:\Program Files\Microsoft SQL Server\110\SDK\Assemblies
  • SQL Server 2014,2016 C:\Program Files\Microsoft SQL Server\120\SDK\Assemblies

You can install all DLLs that you need also from Nuget in one package:

2012: https://www.nuget.org/packages/Unofficial.Microsoft.SQLServer.SMO/

2014: https://www.nuget.org/packages/Unofficial.Microsoft.SQLServer.SMO.2014/

Included DLLs: Microsoft.SqlServer.ConnectionInfo.dll, Microsoft.SqlServer.ConnectionInfoExtended.dll, Microsoft.SqlServer.Management.Sdk.Sfc.dll, Microsoft.SqlServer.Smo.dll, Microsoft.SqlServer.SmoExtended.dll, Microsoft.SqlServer.SqlClrProvider.dll, Microsoft.SqlServer.SqlEnum.dll

You should either use Microsoft.SqlServer.SqlEnum.dll & Microsoft.SqlServer.ConnectionInfo.dll file from that SDK\Assemblies folder that you have used when creating reference to Microsoft.SqlServer.Smo. Or you should install matching assemblies from NuGet. Version 11.0.0.0 of DLLs stands for SQL Server 2014.

See Files and Version Numbers and Create a Visual C# SMO Project in Visual Studio .NET.

If you install only one correct package from NuGet like https://www.nuget.org/packages/Unofficial.Microsoft.SQLServer.SMO.2014/, you should be OK.

Simmer answered 25/4, 2016 at 6:17 Comment(1)
This can also happen if you're using .NET Core but referencing the packages as if they're NetStandard compliant.Wooton

© 2022 - 2024 — McMap. All rights reserved.