Retrieving HD info from CLR SP?

  • Hi all,

    I'm trying to write a little CLR SP in VB to return information on the Harddrives of the server. I'm running into a permissions error:

    **********************************************************

    System.Security.SecurityException: Request for the permission of type 'System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

    at System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet)

    at System.Security.CodeAccessPermission.Demand()

    at System.IO.Directory.GetLogicalDrives()

    at System.IO.DriveInfo.GetDrives()

    at HelloWorld.StoredProcedures.HelloWorld()

    The action that failed was:

    Demand

    The type of the first permission that failed was:

    System.Security.Permissions.SecurityPermission

    The Zone of the assembly that failed was:

    MyComputer

    **********************************************************

    Anybody know why I would get this? I've tried running as SA, as well as the local system account and my domain account (running from my laptop currently, accessing my laptop).

    I can post the code if that would help.

    Thanks

    Doug

  • I do not know about your type of errors, but wouldn't WMI from outside SQL Server be a better, and less intrusive, way of retreiving HD information?

    A pure speculation would be that the Windows account with which the SP is launched does not have enough privs for that specific operation.

    Using the CLR for getting HD info probably seems very convenient but I do not think it is very good practice to introduce that kind of functionality into an RDBMS even though it is now supported.

     

    Hanslindgren

  • I was able to retrieve HD free/availabale space using WMI. This is relatively straightforward process. My preference is to use WMI over CLR as well.

     

    Igor

  • Wich permission set did you use when creating the assembly for SQLServer ?

    CREATE ASSEMBLY xxxx from 'c:\xxxx.dll' WITH PERMISSION_SET =  SAFE | EXTERNAL_ACCESS | UNSAFE 
    I guess for your purposes, you'll need EXTERNAL_ACCESS 
     

    Johan

    Learn to play, play to learn !

    Dont drive faster than your guardian angel can fly ...
    but keeping both feet on the ground wont get you anywhere :w00t:

    - How to post Performance Problems
    - How to post data/code to get the best help[/url]

    - How to prevent a sore throat after hours of presenting ppt

    press F1 for solution, press shift+F1 for urgent solution 😀

    Need a bit of Powershell? How about this

    Who am I ? Sometimes this is me but most of the time this is me

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply