Page 1 of 1

connect SSHClient and MySQL

Posted: Tue 09 Apr 2013 17:08
by ysyang99
Hi

I use MyDAC 7.6.12 for Delphi 2009 and SecureBridge 5.5.1 for Delphi 2009

After sshclient connect , TMyconnection cannot connect MySQL server

error message is "Not overriden in an inherited class" (CRVio.pas line 372)

Please check a source code

Code: Select all

procedure TForm10.Button1Click(Sender: TObject);
var
  OldCursor: TCursor;
begin
  OldCursor := Screen.Cursor;
  try
    Screen.Cursor := crHourGlass;

    ScSSHClient.HostName := 'www.xxxx.com';
    ScSSHClient.User := 'www';
    ScSSHClient.Password := 'xxxx';
    ScSSHClient.Port := 22;
    ScSSHClient.Connect;

{
    ScSSHChannel.SourcePort := 5001;
    ScSSHChannel.DestPort := 3306;
    ScSSHChannel.DestHost := 'localhost';
    ScSSHChannel.Connect;
}


    if ScSSHClient.Connected then
    begin
      With MyConnection1 do
      begin
        IOHandler := MySSHIOHandler;
        Server := 'localhost';
        UserName := 'root';
        Password := 'xxx';
        Connect;
      end;

    end;
  finally
    Screen.Cursor := OldCursor;
  end;
end;

Re: connect SSHClient and MySQL

Posted: Thu 11 Apr 2013 10:34
by DemetrionQ
Hello.

I run your code - everything works with no errors.
The specified error occurs in case if the ReadNoWait method is incorrectly overrided in the class of the object that is transfered to TMyConnection.IOHandler. Please check the CRSSHIOHandler unit - the ReadNoWait method must be present in the public section of the TCRSSHIOHandler class, it must be overrided and set as follows:

Code: Select all

TCRSSHIOHandler = class (TCRIOHandler)
...
public

 {$IFNDEF CLR}class{$ENDIF} function ReadNoWait(Handle: TCRIOHandle; {$IFDEF CLR}var {performance opt}{$ENDIF} buffer: TValueArr; offset, count: integer): integer; override;
...

{$IFNDEF CLR}class{$ENDIF} function TCRSSHIOHandler.ReadNoWait(Handle: TCRIOHandle;
  {$IFDEF CLR}var{performance opt}{$ENDIF} buffer: TValueArr; offset, count: integer): integer;
var
  Channel: TScSSHChannel;
  buf: TBytes;
begin
  Channel := Handle as TScSSHChannel;
  buf := TBytes(buffer);
  Result := Channel.ReadNoWait(buf, offset, count);
end;