CLR UDF Exception In SQL Server 2005
-
03-07-2019 - |
Question
When I try my CLR UDF, I am getting this error:
Msg 6522, Level 16, State 1, Line 1
A .NET Framework error occurred during execution of user-defined routine or aggregate "getFileSize":
System.Security.SecurityException: Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
System.Security.SecurityException:
at System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet)
at System.Security.CodeAccessPermission.Demand()
at System.IO.DirectoryInfo..ctor(String path)
at GetFileInfo.ShowDirectoryName.DirSize(SqlString dir).
Any Idea on how to solve this? I tried to spend some time in BOL but my back is really against the wall right now...
Thanks.
Solution
SQLCLR imposes certain restrictions on what your assembly can do, using Code Access Security.
Read up on the various permission sets in SQL: