views:

543

answers:

3

I would like to include CLR stored procedure deployment in our deployment script (powershell at the moment), however I can't figure out a nice way to do this automatically.

I would have thought there would be a nice command line option to do the same as right-click deploy in Visual studio

+1  A: 

Well, PowerShell itself won't give you much in the way of extra help. You don't mention which version of SQL, so I'll be a bit generic.

Really, all you need to do is have your script file copy the necessary DLLs for your CLR stored procs - PowerShell can copy files like a maniac, so no problem there. Then you need to execute the CREATE ASSEMBLY statement in SQL. PowerShell natively cannot help with this. If you're using SQL 2008, your script can Add-PSSnapin the SQL cmdlet provider, which will give you a cmdlet capable of executing SQL queries - so that gets you your CREATE statement.

If you don't have 2008, you'll have to write a short .NET routine to create a SqlConnection and SqlCommand - not difficult, and entirely possibly in PowerShell.

Next, use the same technique to execute your CREATE PROC statement to actually create the stored proc using the aforementioned assembly.

Zat help? Pity there's nothing more automated, true. MS hasn't spent a lot of brainpower simplifying complex SQL deployment stuff of this nature, I don't think, and CLR stuff adds a bit of extra spice since you have to make the assembly available.

Don Jones
Thanks Don,I was kind of hoping to avoid having to run CREATE PROC as we have lots of CLR stored procedures and don't really want to have to maintain seperate list in the deploy script. I'm not sure how straightforward it would be to interrogate the assembly and automatically pull out the procs
Hainesy
Non-straightforward, unfortunately. This is just an area where MS hasn't, as I said, spent a lot of brainpower, yet. Scripting out a whole database and its objects is easy until CLR stuff becomes involved.
Don Jones
A: 

The SQL Server Publishing Wizard can script CLR stored procs as text. Looks like it converts the binary source of CLR stored procs as some kind of hex encoded text.

voon
+1  A: 

One can use techniques described at http://msdn.microsoft.com/en-us/library/ms345099.aspx to generate deployment script from SSMS. At least this addresses the tedious part of generating a ton of CREATE PROCEDURE statements.

Oleg Zhylin