SQL Server
SQL Server
SSH Tunnel Uncommon Options
See more SSH Tunnel Examples
Demonstrates the UncommonOptions property, which enables optional behavior for uncommon requirements. The default is an empty string; provide a comma-separated list of keywords to enable more than one option. Available keywords are listed in the reference documentation.
Background: This is a catch-all for narrow workarounds that do not warrant their own properties — forcing a specific signature algorithm, disabling the periodic keep-alive, removing weak MACs, bypassing a VPN on Android, and so on. Most applications never set it. When you do, it is usually to satisfy a particular server's quirk or a specific security requirement, and the exact keyword matters, so consult the documented list rather than guessing.
Chilkat SQL Server Downloads
-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls.
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
DECLARE @hr int
DECLARE @sTmp0 nvarchar(4000)
DECLARE @success int
SELECT @success = 0
-- Demonstrates the SshTunnel.UncommonOptions property, which enables optional behavior for
-- uncommon requirements. The default is an empty string, appropriate for most applications.
-- Provide a comma-separated list of keywords to enable more than one option.
DECLARE @tunnel int
EXEC @hr = sp_OACreate 'Chilkat.SshTunnel', @tunnel OUT
IF @hr <> 0
BEGIN
PRINT 'Failed to create ActiveX component'
RETURN
END
-- For example, disable the periodic keep-alive ignore message and remove weak MAC algorithms
-- from those offered. Available keywords are listed in the reference documentation.
EXEC sp_OASetProperty @tunnel, 'UncommonOptions', 'NoKeepAliveIgnoreMsg,no-weak-mac-algs'
EXEC sp_OASetProperty @tunnel, 'DestHostname', 'db.internal.example.com'
EXEC sp_OASetProperty @tunnel, 'DestPort', 5432
DECLARE @sshPort int
SELECT @sshPort = 22
EXEC sp_OAMethod @tunnel, 'Connect', @success OUT, 'ssh.example.com', @sshPort
IF @success = 0
BEGIN
EXEC sp_OAGetProperty @tunnel, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @tunnel
RETURN
END
-- Normally you would not hard-code the password in source. You should instead obtain it
-- from an interactive prompt, environment variable, or a secrets vault.
DECLARE @password nvarchar(4000)
SELECT @password = 'mySshPassword'
EXEC sp_OAMethod @tunnel, 'AuthenticatePw', @success OUT, 'mySshLogin', @password
IF @success = 0
BEGIN
EXEC sp_OAGetProperty @tunnel, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @tunnel
RETURN
END
DECLARE @listenPort int
SELECT @listenPort = 1080
EXEC sp_OAMethod @tunnel, 'BeginAccepting', @success OUT, @listenPort
IF @success = 0
BEGIN
EXEC sp_OAGetProperty @tunnel, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @tunnel
RETURN
END
PRINT 'Tunnel established.'
DECLARE @waitForThreadExit int
SELECT @waitForThreadExit = 1
EXEC sp_OAMethod @tunnel, 'CloseTunnel', @success OUT, @waitForThreadExit
IF @success = 0
BEGIN
EXEC sp_OAGetProperty @tunnel, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @tunnel
RETURN
END
EXEC @hr = sp_OADestroy @tunnel
END
GO