SQL CLR 运行时错误
执行 SQL CLR。开发时一切都很好,测试时一切都很好,然后我们上线了,一切都崩溃了。所以这似乎与 EXTERNAL_ACCESS 安全性有关。我已经确认我们的数据库被标记为可信,数据库所有者是系统管理员,并且程序集被标记为 EXTERNAL_ACCESS 权限。这让我有点困惑到底是什么导致了这个错误。关于可能导致此错误的任何其他想法?
(我隐藏了一些对错误并不重要的东西)
在存储库中查询脏项目时出错:“prc_XXXXXXXXXXXXXXXXXXXXX” System.Data.SqlClient.SqlException:尝试加载程序集 ID 65536 时,Microsoft .NET Framework 中发生错误。服务器可能耗尽资源,或者程序集可能不受 PERMISSION_SET = EXTERNAL_ACCESS 或 UNSAFE 的信任。再次运行查询,或查看文档以了解如何解决程序集信任问题。有关此错误的更多信息: System.IO.FileLoadException:无法加载文件或程序集“myassembleName,Version=1.0.0.0,Culture=neutral,PublicKeyToken=123451234151234”或其依赖项之一。 HRESULT 异常:0x80FC3C2C 系统.IO.FileLoadException: 在 System.Reflection.Assembly._nLoad(AssemblyName fileName、字符串 codeBase、证据 assemblySecurity、程序集位置Hint、StackCrawlMark& stackMark、布尔值 throwOnFileNotFound、布尔值 forIntrospection) 在 System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef、证据 assemblySecurity、StackCrawlMark& stackMark、布尔值 forIntrospection) 在 System.Reflection.Assembly.InternalLoad(字符串 assemblyString,证据 assemblySecurity,StackCrawlMark& stackMark,布尔值 forIntrospection) 在 System.Reflection.Assembly.Load(字符串 assemblyString) 在System.Data.SqlClient.SqlConnection.OnError(SqlException异常,布尔breakConnection) 在 System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) 在System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior,SqlCommand cmdHandler,SqlDataReader dataStream,BulkCopySimpleResultSetbulkCopyHandler,TdsParserStateObject stateObj) 在 System.Data.SqlClient.SqlDataReader.ConsumeMetaData() 在 System.Data.SqlClient.SqlDataReader.get_MetaData() 在System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds,RunBehavior runBehavior,字符串resetOptionsString) 在 System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior、RunBehavior runBehavior、布尔 returnStream、布尔异步) 在 System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior、RunBehavior runBehavior、布尔 returnStream、字符串方法、DbAsyncResult 结果) 在System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior,RunBehavior runBehavior,布尔returnStream,字符串方法) 在System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior行为,字符串方法) 在System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior行为) 在....
Doing a SQL CLR. Everything worked great in development, everything whent great in testing, then we went live, and everything broke. So it seems to have something to do with EXTERNAL_ACCESS security. I have confirmed that our database is marked as trustworthy, the database owner is a sysadmin, and the assembly is marked as EXTERNAL_ACCESS permissions. That leaves me a bit stumpted as to what could cause this error. Any other ideas on what could cause this error?
(I hid a few things that arnt critical to the error)
Error querying repository for dirty items: 'prc_XXXXXXXXXXXXXXXXXXXXX'
System.Data.SqlClient.SqlException: An error occurred in the Microsoft .NET Framework while trying to load assembly id 65536. 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 'myassemblyName, Version=1.0.0.0, Culture=neutral, PublicKeyToken=123451234151234' or one of its dependencies. Exception from HRESULT: 0x80FC3C2C
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.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)
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
at System.Data.SqlClient.SqlDataReader.ConsumeMetaData()
at System.Data.SqlClient.SqlDataReader.get_MetaData()
at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
at System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
at ....
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于某种原因,即使 UI 显示程序集具有外部访问权限(并且它使用这些权限添加到数据库中),但在内部它一定认为由于某种原因它没有这种访问权限。因此,作为解决方案,我运行了这些命令并解决了问题(请注意,我尝试仅运行第二个命令,但它没有解决问题):
ALTER ASSEMBLY [<程序集名称>]
使用 PERMISSION_SET = 不安全的
更改程序集 [<程序集名称>]
带有权限集 = 外部访问权限
For some reason, even though the UI showed that the assembly had external access permissions (and it added to the database with those permissions), internally it must have thought that it didnt have that kind of access for some reason. So as a work around I ran these commands and it fixed the problem (note I tried running just the second command, and it didnt fix it):
ALTER ASSEMBLY [< AssemblyName>]
WITH PERMISSION_SET = UNSAFE
ALTER ASSEMBLY [< AssemblyName>]
WITH PERMISSION_SET = EXTERNAL_ACCESS