使用合并的服务器管理对象(SMO) dll

本文关键字:SMO dll 对象 管理 合并 服务器 | 更新日期: 2023-09-27 17:52:48

目前我正在使用SMO对象来读取SQL服务器的服务器,数据库和表属性。版本、安装日期、大小等属性。客户机计算机(将有多个)将远程访问服务器,但它不能访问SMO库。出于这个原因,我被要求将dll文件合并到要部署在客户端计算机上的载波dll中。我不能再控制在那里安装什么程序。

当代码不运行时,我从合并的dll中没有得到错误,但是当它运行时,我得到一个方法访问异常(见下文)。

我的问题是:是否有可能将SMO dll合并为单个dll并维护功能,或者我最好单独添加dll。或者是否有更好的方法让客户机计算机访问SMO功能?

我担心也许不可能将SMO dll文件合并到一个项目中,需要另一个解决方案,但任何解决我的问题的想法都非常感谢。

我正在使用32位SMO模块。

异常消息:

Attempt by method 'Microsoft.SqlServer.Management.Sdk.Sfc.ObjectLoadInfoManager.LoadHierarchy()' to access method 'Microsoft.SqlServer.Smo.UnSafeInternals.ManagementUtil.EnterMonitor(System.Object)' failed.

堆栈跟踪:

at Microsoft.SqlServer.Management.Sdk.Sfc.ObjectLoadInfoManager.LoadHierarchy() in DummyClass.cs:line0 
at Microsoft.SqlServer.Management.Sdk.Sfc.ObjectLoadInfoManager.GetFirstObjectLoadInfo(Urn urn, Object ci) in DummyClass.cs:line0 
at Microsoft.SqlServer.Management.Sdk.Sfc.ObjectCache.LoadFirstElementVersionless(Urn urn, Object ci) in DummyClass.cs:line0
at Microsoft.SqlServer.Management.Sdk.Sfc.Environment.GetServerVersion(Urn urn, Object ci) in DummyClass.cs:line0
at Microsoft.SqlServer.Management.Sdk.Sfc.Environment.GetObjectInfo(Object ci, RequestObjectInfo req) in DummyClass.cs:line0
at Microsoft.SqlServer.Management.Sdk.Sfc.Enumerator.GetObjectInfo(Object connectionInfo, RequestObjectInfo requestObjectInfo) in DummyClass.cs:line0
at Microsoft.SqlServer.Management.Sdk.Sfc.Enumerator.FixPropertyList(Object connectionInfo, Urn urn, String[] fields, RequestFieldsTypes requestFieldsType) in DummyClass.cs:line0
at Microsoft.SqlServer.Management.Sdk.Sfc.Enumerator.GetData(Object connectionInfo, Request request) in DummyClass.cs:line0
at Microsoft.SqlServer.Management.Smo.ExecutionManager.GetEnumeratorDataReader(Request req) in DummyClass.cs:line0
at Microsoft.SqlServer.Management.Smo.SqlSmoObject.GetInitDataReader(String[] fields, OrderBy[] orderby) in DummyClass.cs:line0
at Microsoft.SqlServer.Management.Smo.SqlSmoObject.ImplInitialize(String[] fields, OrderBy[] orderby) in DummyClass.cs:line0
at Microsoft.SqlServer.Management.Smo.SqlSmoObject.Initialize(Boolean allProperties) in DummyClass.cs:line0
at Microsoft.SqlServer.Management.Smo.SqlSmoObject.OnPropertyMissing(String propname, Boolean useDefaultValue) in DummyClass.cs:line0
at Microsoft.SqlServer.Management.Smo.PropertyCollection.RetrieveProperty(Int32 index, Boolean useDefaultOnMissingValue) in DummyClass.cs:line0
at Microsoft.SqlServer.Management.Smo.PropertyCollection.GetValueWithNullReplacement(String propertyName, Boolean throwOnNullValue, Boolean useDefaultOnMissingValue) in DummyClass.cs:line0
at Microsoft.SqlServer.Management.Smo.PropertyCollection.GetValueWithNullReplacement(String propertyName) in DummyClass.cs:line0
at Microsoft.SqlServer.Management.Smo.Server.get_NetName() in DummyClass.cs:line0
at DummyLibrary.someclass.GetNetName() in DummyClass.cs:line0
at DummyLibrary.someotherclass.GatherSQLBlaBla(YetAnotherClass classvariable, List`1 customerErrorMessages) in DummyClass.cs:line0
at DummyLibrary.StillAnotherClass.GetTheStuff(String stringvar, Int64 aninteger) in DummyClass.cs:line0
at DummyProgram.Main(String[] args) in hubbabubba.Program.cs:line 37
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()

我的合并字符串:

"$(SolutionDir)packages'ILMerge.2.13.0307'ILMerge.exe" /log:log.txt /target:library /closed /out:"$(ProjectDir)bin'$(Configuration)'DummyOutPut.dll"  "$(ProjectDir)bin'$(Configuration)'DummyInput.dll"  "$(ProjectDir)SmoDll'Microsoft.SqlServer.Smo.dll" "$(ProjectDir)SmoDll'Microsoft.SqlServer.SqlEnum.dll" "$(ProjectDir)SmoDll'Microsoft.SqlServer.ConnectionInfo.dll" "$(ProjectDir)SmoDll'Microsoft.SqlServer.Management.Sdk.Sfc.dll" "DummyPath'log4net.dll"

如果这些dll没有合并,而是作为外部dll引用,则不会出现错误。我确实在ilmerge日志中发现了这条令人担忧的日志行:

Duplicate type name: modifying name of the type 'AssemblyVersionInfo' (from assembly 'Microsoft.SqlServer.Management.Sdk.Sfc') to 'Microsoft.SqlServer.Management.Sdk.Sfc1173.AssemblyVersionInfo'

使用合并的服务器管理对象(SMO) dll

在您可以使用SMO对象库之前,还需要'Microsoft SQL Server System CLR Types'库。我们改变了计划,现在正在执行两个msi文件的安装。