Delphes: “Paramètre de l'objet n'est pas définie correctement. Les informations incomplètes ou incohérentes ont été fournis.”

C'est une Fonction qui effectue les opérations suivantes:

  • Créer un Jeton aléatoire avec 8 longueur
  • Insérer le Jeton dans la Base de données
  • Si l'Utilisateur a déjà un jeton, une mise à jour.

  • Si l'Utilisateur n'a pas de jeton, l'insérer.

procedure createToken(BenuNr: integer);
var
  AQ_Query:       TADOQuery;
  strToken:       string;
  intZaehler:     integer;
  const cCharSet: string = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
begin
    //Random String as Token
    SetLength(strToken, 8);
  for intZaehler := 1 to 8 do
  begin
    strToken[intZaehler] := cCharSet[1+Random(Length(cCharSet))];
  end;
  //Inserts the Token into the Database
  with AQ_Query do
  begin
    try
      AQ_Query := TADOQuery.Create(nil);
      ConnectionString := strConnectionString;
      SQL.Text := 'if EXISTS(select * from TOKN where BENU_NR = :paramBenu_NR) begin update TOKN set TOKEN = :paramTOKEN where BENU_NR = :paramBenu_NR end else insert into TOKN (BENU_NR, TOKEN) values (:paramBENU_NR,:paramTOKEN)';
      Prepared := true;
      Parameters.ParamByName('paramBENU_NR').DataType := ftInteger;
      Parameters.ParamByName('paramTOKEN').DataType := ftString;
      Parameters.ParamByName('paramBENU_NR').Value := BenuNr;
      Parameters.ParamByName('paramTOKEN').Value := strToken;
      ExecSQL;    //<< Exception as stated in the title
    finally
      Free;
    end;
  end;
end;

De l'exécution de cette me jette à l'exception comme indiqué dans le titre. J'ai coupé l'exemple ci-dessus vers le bas et le tour est joué: plus aucune exception. Malheureusement, je ne comprends pas pourquoi?

procedure createToken();
var
  AQ_Query:     TADOQuery;
  strToken:     string;
  intZaehler:      integer;
  const cCharSet:  string = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
begin
    //Random String as Token
    SetLength(strToken, 8);
  for intZaehler := 1 to 8 do
  begin
    strToken[intZaehler] := cCharSet[1+Random(Length(cCharSet))];
  end;
  //Inserts the Token into the Database
  with AQ_Query do
  begin
    try
      AQ_Query := TADOQuery.Create(nil);
      ConnectionString := strConnectionString;
      SQL.Text := 'update TOKN set TOKEN = :paramTOKEN where BENU_NR = 1';
      Prepared := true;
      Parameters.ParamByName('paramTOKEN').DataType := ftString;
      Parameters.ParamByName('paramTOKEN').Value := strToken;
      ExecSQL;   //<< No more exception
    finally
      Free;
    end;
  end;
end;

Il semble qu'il y a seulement 1 Paramètre autorisé par SQL. Je suis à l'aide de Delphi 7 et MSSQL Server 2005

Une idée de comment résoudre le premier bloc de code pour le faire fonctionner?

Essayez d'utiliser le générateur de profils sql, pour analyser la requête sql.
Sont les noms des paramètres sensibles à la casse? Parce que vous êtes à l'aide de paramBENU_NR lors du réglage du paramètre, mais paramBenu_NR dans le code - et si elles sont sensibles à la casse, c'est probablement de se plaindre parce que vous n'avez pas spécifié une valeur pour le paramètre dans la requête.

OriginalL'auteur Acron | 2009-08-21