【问题标题】:FileLoadException / Msg 10314 Error Running CLR Stored ProcedureFileLoadException / Msg 10314 错误运行 CLR 存储过程
【发布时间】:2010-09-09 11:50:41
【问题描述】:

尝试运行 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)

【问题讨论】:

    标签: sql-server sqlclr


    【解决方案1】:

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

    USE database_name
    GO
    
    EXEC sp_changedbowner 'sa'
    ALTER DATABASE database_name SET TRUSTWORTHY ON 
    

    【讨论】:

    • sp_changedbowner 修复了它!更多详情请访问support.microsoft.com/kb/918040
    • @JustinDearing 和其他人:请不要将数据库设置为TRUSTWORTHY ON,除非没有其他选择(通常有)。有关详细信息,请在此页面上查看我的answer
    • 为我节省了几个小时!
    • 据我所知,您要在sp_changedbowner 中使用的用户应该与msdbtemp 和其他系统表正在使用的用户相同。至少在我见过的大多数情况下。您通常需要在执行还原时更改此设置,因为它会将运行还原的用户设置为数据库所有者。
    【解决方案2】:

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

    【讨论】:

      【解决方案3】:

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

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

      【讨论】:

        【解决方案4】:

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

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

        【讨论】:

          【解决方案5】:
          ALTER AUTHORIZATION ON DATABASE::mydb TO sa;
          ALTER DATABASE [myDB] SET TRUSTWORTHY ON
          GO
          

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 2012-11-06
            • 1970-01-01
            • 2013-05-12
            • 2015-05-17
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多