views:

136

answers:

2

In the past I've been able to embed a sripting languate (like JScript) inside the SQLCLR, so scripts can be passed as parameters of functions, to perform certain calculations. Here is a simplistic example (the function ssScriptExecute returns a concatenation of all the print's in the script):

select dbo.ssScriptExecute( 'print("Calculation: "+(1+2/3) );' )

-- Calculation: 1.6666666666666665

I'd love to be able to embed a Powershell runtime in the same way. But I've had all sort of problems because the runtime tries to find assemblies by path, and there are no paths inside the SQlCLR. I'm happy to provide more information on the errors I get, but I was wondering if anybody has tried this!

Thanks!

A: 

I thought SQLCLR was restricted to just a certain set of assemblies and PS Automation is not one of them.

Chad Miller
That's correct. But restricted only means not supported. You can still register assembies not in their approved list.
Nestor
Ahh, that didn't occur to me. I looked into creating a PowerShell CLR, noticed System.Management.Automation wasn't one of the blessed assemblies and stopped. It would be interesting if you could get it working.
Chad Miller
one problem I found in embedding JScript (or any DLR based scripting language) is that there is no way to unload the temporary assembly created from the script... this is a leak (every time you run the ssScriptExecute a new assembly gets loaded into memory, and it remains there).. uff
Nestor
A: 

I think the only way to do this is to create a WCF service hosting powershell, and let SQLCLR send the request dbo.ssScriptExecute(...) to that service for execution. Besides from that, I've also successfully embedded paxScript.net in the SQLCLR (an interpreter that does not have the memory leak problems of the DLR languages).

Nestor