目前我正在使用SMO对象来读取SQL Server的Server,Database和Table属性。版本,安装日期,大小等属性。客户端计算机(将有多个)将远程访问服务器,但它将无法访问SMO库。出于这个原因,我被要求将dll文件合并到将在客户端计算机上部署的运营商DLL中。我无法进一步控制那里安装的程序。
当代码没有运行时,我从合并的dll中得不到任何错误,但是当它运行时,我得到一个方法访问异常(见下文)。
我的问题是:是否可以将SMO dll合并为单个dll并保持功能,或者我可以单独添加dll。或者是否有更好的方式让客户端计算机访问SMO功能?
我担心也许不可能将SMO dll文件合并到一个项目中并且需要另一个解决方案,但是非常感谢任何解决我的问题的想法。
我使用的是32位SMO dll。
异常消息:
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'
答案 0 :(得分:0)
在使用SMO对象库之前,还需要“Microsoft SQL Server系统CLR类型”库。我们改变了计划,现在我们正在预先安装两个msi文件。