Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

MSH Host Function In SQL Server 2005

DZone's Guide to

MSH Host Function In SQL Server 2005

·
Free Resource
// part of a sql server CLR function, and example of hosting MSH in sql server 2005

    [Microsoft.SqlServer.Server.SqlFunction]
    public static SqlString sqlmsh(string input)
    {
        string output;
        Runspace runspace = RunspaceFactory.CreateRunspace();
        runspace.Open();
        Pipeline pipeline = runspace.CreatePipeline(input);
        MshObject myobj =   pipeline.Invoke()[0];
        if (myobj.BaseObject is XmlDocument)
         {
            output = (myobj.BaseObject as XmlDocument).InnerXml;
        } else
            output = myobj.ImmediateBaseObject.ToString();
            
        runspace.Close();
        return new SqlString(output);
    }
Topics:

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}