SQL Server
SQL Server
Check the SSH Connection (IsConnected)
See more SSH Examples
Demonstrates how to check whether the connection to the SSH server still exists. The IsConnected property is checked first, and SendIgnore is then used to confirm the link for certain.
Background: These checks differ in strength.
IsConnected simply reports the state the object already knows and involves no network activity, so it can stay true after a silent network failure the operating system has not yet noticed. SendIgnore sends an SSH IGNORE message — discarded by the peer by design — which exercises the real write path and is therefore much stronger evidence the link is usable. CheckConnection sits between the two, peeking at the socket without sending anything.Chilkat SQL Server Downloads
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
DECLARE @hr int
DECLARE @sTmp0 nvarchar(4000)
DECLARE @success int
SELECT @success = 0
-- Demonstrates how to check whether the connection to the SSH server still exists.
DECLARE @ssh int
EXEC @hr = sp_OACreate 'Chilkat.Ssh', @ssh OUT
IF @hr <> 0
BEGIN
PRINT 'Failed to create ActiveX component'
RETURN
END
DECLARE @port int
SELECT @port = 22
EXEC sp_OAMethod @ssh, 'Connect', @success OUT, 'ssh.example.com', @port
IF @success = 0
BEGIN
EXEC sp_OAGetProperty @ssh, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @ssh
RETURN
END
-- IsConnected reports the state already known to the Ssh object. It does not perform a
-- network round trip.
DECLARE @connected int
EXEC sp_OAGetProperty @ssh, 'IsConnected', @connected OUT
IF @connected
BEGIN
-- Verify for certain by sending an SSH IGNORE message, which exercises the actual write
-- path. The server sends no reply, but a successful send proves the link is writable.
EXEC sp_OAMethod @ssh, 'SendIgnore', @connected OUT
END
PRINT 'connected = ' + @connected
EXEC sp_OAMethod @ssh, 'Disconnect', NULL
-- After disconnecting, the object reports that it is no longer connected.
EXEC sp_OAGetProperty @ssh, 'IsConnected', @connected OUT
PRINT 'connected = ' + @connected
EXEC @hr = sp_OADestroy @ssh
END
GO