SQLCLRProject
Welcome to the homepage for the SQLCLRProject! For you that already know what it is and want the latest and the greatest, go to here. For the rest of you - read on.
What is the SQLCLRProject?
The short answer to what it is; it’s a tool that allows you to deploy .NET assemblies to SQL Server (version 2005 and later). Under the covers it uses MSBUILD tasks. It deploys the assembly(ies) to the database as well as creating the T-SQL procedures/functions/triggers/etc. In addition, it also creates T-SQL scripts during the deployment process.
The tool can be used both from command-line as well as by using a GUI and also as an add-in to Visual Studio 2005/2008 (with it’s own project type and item templates).
The tool started out as a very, very basic command line tool, but it evolved over time and consists now of four parts:
- yukondeploy.dll - this is the underlying dll that contains the various MSBUILD tasks and does all the heavy lifting. You can use yukondeploy together with build scripts from the command-line directly.
- DeployProperties.exe - a stand-alone UI executable which allows you to generate (and execute) build scripts from a GUI.
- VSTemplates - Visual Studio (2005 and later) C-Sharp and VB.NET project- and item-templates to create .NET assemblies that can be deployed to SQL Server.
- DeployAddIn - an add-in for Visual Studio, which allows you to generate the necessary build files and do deployment from inside VS based on the VS projects you have created off the templates above.
Features
Here follows some of the major features of the SQLCLRProject tool.
- Automatically deploy an assembly to SQL Server and create the T-SQL methods from the .NET functions. This can be done from the command line, the DeployProperties GUI executable as well as from inside the Visual Studio IDE.
- Automatic creation of T-SQL deployment scripts.
- Automatic creation of T-SQL DML scripts to test the generated T-SQL methods.
- Ability to alter an assembly and only deploy newly added methods from the assembly.
- Ability to create objects in a non default schema: “schemaname.objectname”.
- Assigning of default values to parameters in the T-SQL generated objects.
- When re-deploying a UDT, instead of dropping the whole table - the deploy task can create a new column in the table in question and transfer all the data from the original column over to the new column, and then drop the original column.
- Debug facilities from inside the VS IDE.
Visual Studio
By now, especially the ones of you that are using Visual Studio, you may wonder what the differences are between the SQLCLRProject and the VS built-in project type for SQL Server; SQL Server Project. After all, the SQL Server Project is built in into VS. Well, quite a lot:
| Feature | SQLCLRProject | VS built-in |
| Specific VS project type and item templates | Yes | Yes |
| Automatic deployment of assemblies and creation of T-SQL objects | Yes | Yes |
| Debugging support | Yes | Yes |
| Automatic creation of T-SQL deployment scripts | Yes | - |
| Automatic creation of T-SQL DML scripts for testing of the created objects | Yes | - |
| Alter an assembly and only deploy newly added methods | Yes | - |
| Create objects in a non-default schema | Yes | - |
| Define parameters in the .NET methods to have default values in T-SQL | Yes | - |
| Define parameters in .NET to be created with different names in T-SQL | Yes | - |
| Redeploying an UDT without manually dropping tables/columns depending on the UDT | Yes | - |
In addition to the above, the SQLCLRProject works both against SQL Server 2005 as well as against SQL Server 2008, whereas in Visual Studio 2005 the VS built-in project does not work against SQL Server 2008.
Support
When installing the tool, documentation are installed as well. The documentation covers all the different parts of SQLCLRProject.
If you:
- need more help
- come across things that don’t work as you think they should
- you come across bugs (as unlikely as that might be - yeah right :-))
- you have ideas how to evolve SQLCLRProject,
please post a comment on this page or write me an email.
Download
You can download it from here.
January 16, 2008 at 1:40 pm
Niels, This is a great tool that I plan on using. Does it have any features to help out with deploying an assembly that accesses a web service? I.e. can it auto SGEN the serializer assemblys and deploy that as well?
January 16, 2008 at 2:03 pm
Hi Brett,
No, at the moment It cannot handle web-service references (even though, you can have other assembly references in your project and those will be handled). This is definitely something to look at for a new feature.
Niels
January 28, 2008 at 9:58 pm
Woudl you be willing to make the source available if we agreed not to post it anywhere?
January 29, 2008 at 6:39 am
Kathy,
Just out of curiosity - what improvements were you thinking of doing when having the source?
I have sent you an email.
Niels
January 29, 2008 at 6:03 pm
This seems like a great tool. I was looking at writing a similar utility to automate our deployment of SQL CLR code, but fortunately you have done most of the work!
Is it possible to get more information about how dependencies are registered along with the binary representation of the assembly?
When I reference a single dependency
SqlClrCode.dll -> Constants.dll
The DeployAssembly task works exactly as expected. I get both dlls registered in sql server, with the second as a dependency of the first.
However, in real life, my project has a much more complicated dependency structure. Something like
SqlClrCode.dll -> BusinessObjects.dll -> XML.dll -> Data.dll -> Constants.dll
In this situation, DeployAssembly will fail with the message “Assembly ‘xml, version=1.0.2949.20834, culture=neutral, publickeytoken=039109d9ceb6f2f1.’ was not found in the SQL catalog.”
I did some experiments with trying to register the assembly as a file, and came across a possibly related problem.
If I build a regular, signed C# project with the same SqlCLR code and dependencies in it, I can then say
CREATE ASSEMBLY [MyCLR] FROM ‘C:\MyCLR\bin\Debug\MyCLR.dll’ WITH PERMISSION_SET = UNSAFE
This works, and pulls in all the dependent assemblies.
When I try to register the assembly from my SqlClrProject project (also signed) in this fashion, however, I get the error “The module being executed is not trusted. Either the owner of the database of the module needs to be granted authenticate permission, or the module needs to be digitally signed.”
What is special about the SqlClrProject dll that prevents it from being registered in this fashion?
Any help or insight is appreciated.
Doug
January 30, 2008 at 8:05 am
Doug,
As you know - this should now have been fixed.
For you that wants the fixed file 9or to download the whole project) go to the download page.
Niels
March 7, 2008 at 4:49 pm
Hi Niels,
Kathy was asking about source code … I would be interested as well
I’m using your tool to deploy my assemblies, but I have many servers to handle. I’d like to add some kind of automation, depending on my needs!
Would it be possible?
Regards,
Christophe
March 21, 2008 at 10:25 pm
I have just started using Sql Clr assemblies and came across your tool trying to decide how to script them to install at customer sites, as I work for a software vendor.
I came across your tool, and it sounds great - I can’t find any information however on restrictions on using it, cost, etc. Are there any restrictions on its use or distribution? i.e. Is it free for us to use both internally, and as a component integrated into our install packages that they supply to customers?
Also, currently, all of our DB updates are scripted in TSQL, and we run a single upgrade utility that uses a sequence file to determine the order in which to run the scripts. I had been hoping to integrate the SQL CLR installs into that same structure as just another script or set of scripts. I’m not sure whether your tool could fit into that model, or if not, whether you’d be willing to share the source and we might be able to integrate the essential logic into our installation utility?
Thank you very much!
March 26, 2008 at 4:46 pm
Hi,
Currently, we are migrating our TSQL stored procedure to SQL CLR stored procedure. Is your tool capable to convert the existing SP and provide us .NET code to create CLR SP?
There are 100s of SP and it is very big task to convert all. It would be great if there is any tool available which can do that for us. Can you please let me know if you have any idea about such a tool.
Thanks & Regards,
Hitesh
March 27, 2008 at 5:20 pm
Hitesh, I doubt there’s a way to automate that kind of move, but in any case, you may want to rethink migrating all stored procedures to SQL CLR. There are performance concerns with the context switching that is necessary to run SQL CLR stored procedures. The documentation I’ve seen advises that they should be used only for tasks that are not easily or efficiently do-able in TSql - for example regular expression string validations.
May 15, 2008 at 9:01 pm
This is great, I’ve been using this since an earlier version ~2006.
Noticed some things: v.2.6 when deploying I keep getting a message after attempting to CREATE ASSEMBLY that it can not find the deployproperties assembly. I see it up there, the information seems to match. Rolled back to 2.5.
In v2.5 - In an Aggregate: Accumulate([SqlFacet(MaxSize=8000)] SqlString value) does not seem to work, it keeps getting defined as @Value nvarchar(50). The [return: SqlFacet(MaxSize=-1)] for Terminate() works find though.