SQL .NET assemblies
I'd like it for a CLR function I wrote to be available to every database on a specific instance.
Any advice on how I would go about doing this? Obviously I want to avoid any security issues and (of course) the labor of deploying the DLL to each and every db that will be using it.
Hi AcidRaZor,
I've developed several C# DLL's for use in both SQL stored procs and functions.
As for the security you will be fine if you restrict the access the dll has in the system. If its unrestricted you are giving it access to the OS and file system which I dont recommend unless you're 100% sure it needs to operate on that level.
Restricting the access to the function for the users that require access (I'd never recommend admin access to the SQL user that can access the DLL. This is because I would not allow the application using this to have admin rights in the SQL instance.)
The DLL's contained methods/subs should be internal only except for the methods that recieve, and return the data.
The next step is really to make sure no one gets thier hands on the DLL or the project.
With the security out of the way we can talk about the deployment.
Its quick and easy, and can be done covering many SQL instances through SSMS by clicking on programmibility and then right clicking on assemblies, add, and then navigate to the dll (on the computer youre working on as this is done remotely) and upload.
Then its just to create the SP's that reference the DLL and youre good to go.
I'm going to say this once. The performance boost you get from ie. string manipulation from SQL CLR Functions and SP's is WELL WORTH YOUR TIME. SQL varchars are not managed using a garbage colector or the string intern pool.
If you do one thing today read this link.
http://www.simple-talk.com/sql/t-sql-programming/clr-performance-testing/
The below link is a simple and easy to use way to get this working.
http://blog.sqlauthority.com/tag/clr/
Good luck with it.