目前我正在使用SMO對象來讀取SQL Server的服務器,數據庫和表屬性。像版本,安裝日期,大小等屬性。客戶端計算機(將有多個)將遠程訪問服務器,但它無法訪問SMO庫。由於這個原因,我被要求將dll文件合併到要部署在客戶端計算機上的載體dll中。我無法進一步控制那裏安裝的程序。MethodAccessException使用合併的服務器管理對象(SMO)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'