Re: SqlServer 2005 CLR integration using DirectoryServices by Willy
Willy
Wed Feb 22 09:22:16 CST 2006
"HowardB" <howard.birkett@collercapital.com> wrote in message
news:1140604268.558973.45320@g44g2000cwa.googlegroups.com...
| Using a VisualStudio 2005 Sql Server Database project template, I want
| to
| access DirectoryServices (AD) from a UDF, but cannot add a reference to
|
| directoryservices.dll (legally) into the c# project, and if I add it
| illegally (in the XML), i get a sql error saying that DirectoryServices
|
| is not in the SQL catalog.
|
| Question: can I access DirectoryServices from Sql Server in either a
| UDF or SP. If the answer is yes - then how?
|
| Thanks
| Howard
|
Sure it's possible, but you should know that this is quite unsafe and
currently unsupported by MS.
What you should do first is to marks your database as THRUSTWORTHY, by means
of:
ALTER DATABASE xxxx Set THRUSTWORTHY= ON
then you need to load the DirectoryServices assembly in the DB, like:
CREATE ASSEMBLY DirectoryServices from
'c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\system.directoryservices.dll'
WITH PERMISSION_SET = UNSAFE
this will show you this warning message:
Warning: The Microsoft .Net frameworks assembly 'system.directoryservices,
version=2.0.0.0, culture=neutral, publickeytoken=b03f5f7f11d50a3a,
processorarchitecture=msil.' you are registering is not fully tested in SQL
Server hosted environment.
Once this is done you can load your assembly.
CREATE ASSEMBLY aaaa from 'your_assembly_Path' WITH PERMISSION_SET = UNSAFE
Note the UNSAFE permission set, check SQL online to see what this means ;-)
Willy.