title: Delphi: “Parameter object is improperly defined. Inconsistent or incomplete information was provided.”
body: <p>This is a Function that does the following:</p>
  
  <blockquote>
    <ul>
    <li>Create a random Token with 8 length</li>
    <li>Insert that Token into the Database</li>
    <li><blockquote>
      <p>If the User has already a token, update it.</p>
    </blockquote></li>
    <li><blockquote>
      <p>If the User has no token, insert it.</p>
    </blockquote></li>
    </ul>
  </blockquote>
  
  <pre><code>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;    //&lt;&lt; Exception as stated in the title
      finally
        Free;
      end;
    end;
  end;
  </code></pre>
  
  <p>Executing this throws me the exception as stated in the title. I cut the above example down and voila: no more exception. Unfortunately I don't get why?</p>
  
  <pre><code>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;   //&lt;&lt; No more exception
      finally
        Free;
      end;
    end;
  end;
  </code></pre>
  
  <p>It seems that there is only 1 Parameter allowed per SQL. I am using Delphi 7 and MSSQL Server 2005</p>
  
  <p><strong>Any idea how to fix the first code block to make it work?</strong></p>