MSSQL加载程序集错误

时间:2017-03-29 16:30:46

标签: sql-server .net-assembly

运行在MSSSQL中使用程序集的函数时,我收到以下错误:

  

Msg 10314,Level 16,State 11,Line 36   尝试加载程序集ID 65800时,Microsoft .NET Framework中发生错误。服务器可能资源不足,或者PERMISSION_SET = EXTERNAL_ACCESS或UNSAFE可能不信任程序集。再次运行查询,或检查文档以了解如何解决程序集信任问题。有关此错误的更多信息:   System.IO.FileLoadException:无法加载文件或程序集'exporttoexcel,Version = 0.76.0.0,Culture = neutral,PublicKeyToken = f73371c9a1809a3f'或其依赖项之一。来自HRESULT的异常:0x80FC80F1   System.IO.FileLoadException:      在System.Reflection.Assembly._nLoad(AssemblyName fileName,String codeBase,Evidence assemblySecurity,Assembly locationHint,StackCrawlMark& stackMark,Boolean throwOnFileNotFound,Boolean forIntrospection)      在System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef,Evidence assemblySecurity,StackCrawlMark& stackMark,Boolean forIntrospection)      在System.Reflection.Assembly.InternalLoad(String assemblyString,Evidence assemblySecurity,StackCrawlMark& stackMark,Boolean forIntrospection)      在System.Reflection.Assembly.Load(String assemblyString)

但是在我重新创建函数和汇编之后,一切都运行良好了一段时间:

DROP FUNCTION [dbo].[fnExportToExcel]
DROP ASSEMBLY ExcelExporter

CREATE ASSEMBLY ExcelExporter  
AUTHORIZATION [DOMAIN\ACCOUNT]
FROM 'ExportToExcel.dll'
WITH PERMISSION_SET = UNSAFE

CREATE FUNCTION [dbo].[fnExportToExcel](@Query [nvarchar](max), @FilePath [nvarchar](max), @FileName [nvarchar](max), @SheetNames [nvarchar](max))
RETURNS [nvarchar](max) WITH EXECUTE AS CALLER
AS 
EXTERNAL NAME ExcelExporter.[ExportToExcel_DLL.cls_ExcelExport].[ExportToExcel]
GO

任何可能导致MSSQL丢失程序集引用的想法?

1 个答案:

答案 0 :(得分:3)

我使用了Alex K提供的链接。 Link

在我的情况下,运行此命令解决了问题:

EXEC sp_changedbowner 'sa'