Question

The following error occurs at the line I've indicated below. And I can't figure our why it's getting this error.

Project ChirpSR.exe raised exception class $C0000005 with message 'access violation at 0x00e8d088: read of address 0x00000000'.

The code below is from an auto generated proxy class for a DataSnap Server.

interface

uses Data.DBXCommon, Data.DBXClient, Data.DBXDataSnap, Data.DBXJSON, Datasnap.DSProxy, System.Classes, System.SysUtils, Data.DB, Data.SqlExpr, Data.DBXDBReaders, Data.DBXCDSReaders, Data.DBXJSONReflect;

....
type
  TServerMethods1Client = class(TDSAdminClient)
  private
    FEchoStringCommand: TDBXCommand;
    FReverseStringCommand: TDBXCommand;
    FGetValleysCommand: TDBXCommand;
    FUpdateUserCommand: TDBXCommand;
  public
    constructor Create(ADBXConnection: TDBXConnection); overload;
    constructor Create(ADBXConnection: TDBXConnection; AInstanceOwner: Boolean); overload;
    destructor Destroy; override;
    function EchoString(Value: string): string;
    function ReverseString(Value: string): string;
    function GetValleys: TJSONValue;
    function UpdateUser(jsonobj: TJSONObject): Integer;
  end;
....
// This function runs fine
function TServerMethods1Client.GetValleys: TJSONValue;
begin
  if FGetValleysCommand = nil then
  begin
    FGetValleysCommand := FDBXConnection.CreateCommand;
    FGetValleysCommand.CommandType := TDBXCommandTypes.DSServerMethod;
    FGetValleysCommand.Text := 'TServerMethods1.GetValleys';
    FGetValleysCommand.Prepare;
  end;
  FGetValleysCommand.ExecuteUpdate;
  Result := TJSONValue(FGetValleysCommand.Parameters[0].Value.GetJSONValue(FInstanceOwner));
end;

// This function errors at the highlighted line
function TServerMethods1Client.UpdateUser(jsonobj: TJSONObject): Integer;
begin
  if FUpdateUserCommand = nil then
  begin
    FUpdateUserCommand := FDBXConnection.CreateCommand;  <============= Error Here
    FUpdateUserCommand.CommandType := TDBXCommandTypes.DSServerMethod;
    FUpdateUserCommand.Text := 'TServerMethods1.UpdateUser';
    FUpdateUserCommand.Prepare;
  end;
  FUpdateUserCommand.Parameters[0].Value.SetJSONValue(jsonobj, FInstanceOwner);
  FUpdateUserCommand.ExecuteUpdate;
  Result := FUpdateUserCommand.Parameters[1].Value.GetInt32;
end;
....

The server is running, otherwise the first function would error.

I'm stumped.

I'm also new to DataSnap.

Was it helpful?

Solution

Project ChirpSR.exe raised exception class $C0000005 with message 'access violation at 0x00e8d088: read of address 0x00000000'.

The error message suggests what you have FDBXConnection = nil. Since CreateCommand is virtual method, calling TDBXConnection(nil).CreateCommand will produce exception you presented.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top