问题
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?
回答1:
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.
来源:https://stackoverflow.com/questions/36832965/c-sharp-smo-and-sqlenum-references-error