Sample code for 30+ languages & platforms
SQL Server Requires Chilkat v11.6.0+

Configure MCP Connection Settings

See more MCP Client Examples

Demonstrates Mcp.SetConnectionSettings, which copies connection settings -- such as an HTTP proxy, SOCKS proxy, bind IP address, and TLS options -- from a Socket and applies them before connecting.

Background. This is optional; if not used, a direct connection is made. It is useful when the MCP server must be reached through a proxy or with specific TLS settings.

Chilkat SQL Server Downloads

SQL Server
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
    DECLARE @hr int
    DECLARE @sTmp0 nvarchar(4000)
    DECLARE @success int
    SELECT @success = 0

    DECLARE @mcp int
    EXEC @hr = sp_OACreate 'Chilkat.Mcp', @mcp OUT
    IF @hr <> 0
    BEGIN
        PRINT 'Failed to create ActiveX component'
        RETURN
    END

    --  Configure connection settings on a Socket -- such as an HTTP proxy, SOCKS proxy, bind IP address,
    --  or TLS options -- and apply them to the MCP client before connecting.  This is optional; if not
    --  used, a direct connection is made.
    DECLARE @sock int
    EXEC @hr = sp_OACreate 'Chilkat.Socket', @sock OUT

    EXEC sp_OASetProperty @sock, 'HttpProxyHostname', 'proxy.example.com'
    EXEC sp_OASetProperty @sock, 'HttpProxyPort', 8080

    EXEC sp_OAMethod @mcp, 'SetConnectionSettings', @success OUT, @sock
    IF @success = 0
      BEGIN
        EXEC sp_OAGetProperty @mcp, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @mcp
        EXEC @hr = sp_OADestroy @sock
        RETURN
      END

    EXEC sp_OAMethod @mcp, 'Connect', @success OUT, 'https://learn.microsoft.com/api/mcp'
    IF @success = 0
      BEGIN
        EXEC sp_OAGetProperty @mcp, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @mcp
        EXEC @hr = sp_OADestroy @sock
        RETURN
      END

    PRINT 'Connected using the configured connection settings.'

    EXEC @hr = sp_OADestroy @mcp
    EXEC @hr = sp_OADestroy @sock


END
GO