By default when you create a CLR trigger, VS 2008 will deploy it as a SAFE trigger:
CREATE ASSEMBLY HelloWorld
FROM @SamplesPath + ‘HelloWorld\CS\HelloWorld\bin\debug\HelloWorld.dll’
WITH PERMISSION_SET = SAFE;
This is good, you always want to start with the minimal permissions but as in my previous example, when you want to work with the file system you’ll need the “external access” permission for your assembly.
The good news is that in the project properties you can set this very easy:
But the database server won’t accept this so easily. You’ll need to set the database in the Thrustworthy state.
It cost me a bit of searching but the way to do this is:
Use Master
alter database XYZ set trustworthy on
And now you can play.
Security warning: This setting is good for development, but in production circumstances you’ll need some other tricks. Next post when I have solved this problem!