17.06.2013 Views

Beginning Microsoft SQL Server 2008 ... - S3 Tech Training

Beginning Microsoft SQL Server 2008 ... - S3 Tech Training

Beginning Microsoft SQL Server 2008 ... - S3 Tech Training

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 12: Stored Procedures<br />

408<br />

feed or stock quote), even though the structure and complex communications required would have<br />

ruled out such a function in prior versions.<br />

Without going into too much detail on them for now, let’s look at the syntax for adding an assembly to<br />

your database:<br />

CREATE ASSEMBLY AUTHORIZATION FROM <br />

WITH PERMISSION_SET = [SAFE | EXTERNAL_ACCESS | UNSAFE]<br />

The CREATE ASSEMBLY part of things works as pretty much all our CREATE statements have — it indicates<br />

the type of object being created and the object name.<br />

Then comes the AUTHORIZATION — this allows you to set a context that the assembly is always to run<br />

under. That is, if it has tables it needs to access, how you set the user or rolename in AUTHORIZATION<br />

will determine whether it can access those tables or not.<br />

After that, we go to the FROM clause. This is essentially the path to your assembly, along with the manifest<br />

for that assembly.<br />

Finally, we have WITH PERMISSION_SET. This has three options:<br />

❑ SAFE: This one is, at the risk of sounding obvious, well . . . safe. It restricts the assembly from<br />

accessing anything that is external to <strong>SQL</strong> <strong>Server</strong>. Things like files or the network are not available<br />

to the assembly.<br />

❑ EXTERNAL_ACCESS: This allows external access, such as to files or the network, but requires<br />

that the assembly still run as managed code.<br />

❑ UNSAFE: This one is, at the risk of again sounding obvious, unsafe. It allows your assembly not<br />

only to access external system objects, but also to run unmanaged code.<br />

I cannot stress enough the risks you are taking when running .NET assemblies in<br />

anything other than SAFE mode. Even in EXTERNAL_ACCESS mode you are allowing<br />

the users of your system to access your network, files, or other external resources in<br />

what is essentially an aliased mode — that is, they may be able to get at things that<br />

you would rather they not get at, and they will be aliased on your network to whatever<br />

your <strong>SQL</strong> <strong>Server</strong> login is while they are making those accesses. Be very, very<br />

careful with this stuff.<br />

.NET assemblies will be discussed extensively in Professional <strong>SQL</strong> <strong>Server</strong> <strong>2008</strong> Programming.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!