FileLoadException / Msg 10314运行CLR存储过程时出错

时间:2008-09-16 13:39:34

标签: sql-server sqlclr

尝试运行CLR存储过程时收到以下错误。非常感谢任何帮助。

Msg 10314, Level 16, State 11, Line 1
An error occurred in the Microsoft .NET Framework while trying to load assembly id 65752. The server may be running out of resources, or the assembly may not be trusted with PERMISSION_SET = EXTERNAL_ACCESS or UNSAFE. Run the query again, or check documentation to see how to solve the assembly trust issues. For more information about this error: 
System.IO.FileLoadException: Could not load file or assembly 'orders, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. An error relating to security occurred. (Exception from HRESULT: 0x8013150A)
System.IO.FileLoadException: 
   at System.Reflection.Assembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection)
   at System.Reflection.Assembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection)
   at System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)
   at System.Reflection.Assembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)
   at System.Reflection.Assembly.Load(String assemblyString)

5 个答案:

答案 0 :(得分:69)

执行下面的SQL命令,问题似乎已得到解决。

USE database_name
GO

EXEC sp_changedbowner 'sa'
ALTER DATABASE database_name SET TRUSTWORTHY ON 

答案 1 :(得分:8)

使用任何CPU配置构建项目。在使用x86配置编译我自己的项目并尝试在x64 SQL服务器上运行时,我遇到了这个问题。

答案 2 :(得分:2)

应用了上述所有建议,但失败了。 然后我用“Any CPU”选项重新编译了我的源代码,它运行了!

此链接有助于: SQL Server failed to load assembly with PERMISSION

答案 3 :(得分:0)

你的程序集是否提交I / O文件?如果是这样,您必须授予程序集权限才能执行此操作。在SSMS:

  1. 展开“数据库”
  2. 展开数据库的节点
  3. 展开“可编程性”
  4. 展开“装配”
  5. 右键单击您的程序集,选择“属性”
  6. 在“常规”页面上,将“权限设置”更改为“外部访问”

答案 4 :(得分:0)

ALTER AUTHORIZATION ON DATABASE::mydb TO sa;
ALTER DATABASE [myDB] SET TRUSTWORTHY ON
GO