Question

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!

Was it helpful?

Solution

I use il code injection to modified System.Automation.Management. make variable version in GetPSVersionTable() be "2.0" then i can run Powershell Code in SQL Server.

Be sure reference this modified dll in your visual studio project.

http://www.box.net/shared/57122v6erv9ss3aopq7p

btw, automated registering all dll you needed with running powershell in SQL

you can use this ps1 code

http://www.box.net/shared/tdlpu1875clsu8azxq4b

OTHER TIPS

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).

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top