7

I'm trying to insert a record into a table in a 3-tier database setup, and the middle-tier server generates the error message above as an OLE exception when it tries to add the first parameter to the query.

I've Googled this error, and I find the same result consistently: it comes from having a colon in a string somewhere in your query, which b0rks ADO's SQL parser. This is not the case here. There are no spurious colons anywhere. I've checked and rechecked the object definition against the schema for the table I'm trying to insert into. Everything checks out, and this has my coworkers stumped. Does anyone know what else could be causing this? I'm at my wits' end here.

I'm using Delphi 2007 and SQL Server 2005.

1
  • @Mason - Are you using parameters? If not, does setting ParamCheck := False help? Apr 3, 2009 at 6:36

13 Answers 13

4

I can get this error, using Delphi 2007 and MSSQL Server 2008, and I found a workaround. (which is pretty crappy IMHO, but maybe its useful to you if yours is caused by the same thing.)

code to produce the error:

with TADOQuery.Create(nil)
do try

   Connection := ADOConnection;

   SQL.Text := ' (SELECT * FROM Stock WHERE  InvCode = :InvCode ) '
              +' (SELECT * FROM Stock WHERE  InvCode = :InvCode ) ';

   Prepared := true;

   Parameters.ParamByName('InvCode').Value := 1;

   Open;  // <<<<< I get the "parameter object is...etc. error here.

 finally
   Free;
 end;

I found two ways to fix it:

1) remove the brackets from the SQL, ie:

   SQL.Text := ' SELECT * FROM Stock WHERE  InvCode = :InvCode  '
              +' SELECT * FROM Stock WHERE  InvCode = :InvCode  ';

2) use two parameters instead of one:

with TADOQuery.Create(nil)
do try

   Connection := ADOConnection;

   SQL.Text := ' (SELECT * FROM Stock WHERE  InvCode = :InvCode1 ) '
              +' (SELECT * FROM Stock WHERE  InvCode = :InvCode2 ) ';

   Prepared := true;

   Parameters.ParamByName('InvCode1').Value := 1;
   Parameters.ParamByName('InvCode2').Value := 1;

   Open;  // <<<<< no error now.

 finally
   Free;
end;
3

I found this thread while searching the previously mentioned Exception message. In my case, the cause was an attempt to embed a SQL comment /* foo */ into my query.sql.text.

(I thought it would have been handy to see a comment go floating past in my profiler window.)

Anyhow - Delphi7 hated that one.

1
  • The same for me, in delphi 2010. I was adding a "-- foo" comment, though.
    – Paolo M
    Oct 9, 2013 at 12:36
2

Here a late reply. In my case it was something completely different.

I tried to add a stored procedure to the database.

Query.SQL.Text :=
'create procedure [dbo].[test]' + #13#10 +
'@param int ' + #13#10 +
'as' + #13#10 + 
'-- For the parameter you can pick two values:' + #13#10 + 
'-- 1: Value one' + #13#10 + 
'-- 2: Value two';

When I removed the colon (:) it worked. As it saw the colon as a parameter.

1

I just encountered this error myself. I'm using Delphi 7 to write to a 2003 MS Access database using a TAdoQuery component. (old code) My query worked fine directly in MS Access, but fails in Delphi through the TAdoQuery object. My error came from a colon (apologies to the original poster) from a date/time value.

As I understand it, Jet SQL date/time format is #mm/dd/yyyy hh:nn:ss# (0 left-padding is not required).

If the TAdoQuery.ParamCheck property is True then this format fails. (Thank you posters!) Two work-arounds are: a) set ParamCheck to False, or b) use a different date/time format, namely "mm/dd/yyyy hh:nn:ss" (WITH the double quotes).

I tested both of these options and they both worked.

Even though that double-quoted date/time format isn't the Jet date/time format, Access is pretty good at being flexible on these date/time formats. I also suspect it has something to do with the BDE/LocalSQL/Paradox (Delphi 7's native SQL and database engine) date/time format (uses double quotes, as above). The parser is probably designed to ignore quoted strings (double quotes are the string value delimiter in BDE LocalSQL), but may stumble somewhat on other non-native date/time formats.

SQL Server uses single quotes to delimit strings, so that might work instead of double quotes when writing to SQL Server tables (not tested). Or maybe the Delphi TAdoQuery object will still stumble. Turning off ParamCheck in that case may be the only option. If you plan to toggle the ParamCheck property value in code, you'll save some processing time by ensuring the SQL property is empty before enabling it, if you're not planning on parsing the current SQL.

1

I'm facing the same error described in your question. I've traced the error into ADODB.pas -> procedure TParameters.AppendParameters; ParameterCollection.Append(Items[I].ParameterObject).

By using breakpoints, the error was raised, in my case, by a parameter which should fill a DateTime field in the database and I've never filled up the parameter. Setting up the parameter().value:='' resolved the issue (I've tried also with varNull, but there is a problem - instead of sending Null in the database, query is sending 1 - the integer value of varNull).

PS: I know is a 'late late late' answer, but maybe somebody will reach at the same error.

3
  • Had a problem like that, but got it sending NULL (se my answer) Mar 31, 2011 at 11:58
  • I'm having the same problem right now, which sometimes happens, sometimes not, and I've also managed to trace it down to TParameters.AppendParameters. I noticed that the parameter that was causing the problem was being assigned the value NULL. Changing it to Unassigned seems to have fixed the problem. But what really bugs me is the fact that the error would only sometimes occur. Mar 24, 2014 at 17:43
  • "I've tried also with varNull, but there is a problem - instead of sending Null in the database, query is sending 1 - the integer value of varNull" - you don't create a NULL Variant by literally assigning varNull itself to the Variant. You need to set the TVarData(Variant).VType field to varNull instead. You can do that manually, or you can simply assign the result of the Variants.Null() function to the Variant instead. Apr 26, 2021 at 17:58
0

If I remember well, you have to explicit put NULL value to the parameter. If you are using a TAdoStoredProc component, you should do this in design time.

0

Are you using any threading? I seem to remember getting this error when a timer event started a query while the ADO connection was being used for another synchronous query. (The timer was checking a "system available" flag every minute).

0

Have you set the DataType of the parameter or did you leave it as ftUnknown?

0
0

I have also had the same problem, but with a dynamic command (e.g. an Update statement).
Some of the parameters could be NULL.
The only way i could get it working, was setting the parameter.DataType := ftString and parameter.Size := 1 and not setting the value.

cmdUpdate := TADOCommand.Create(Self);
try
  cmdUpdate.Connection := '**Conections String**';
  cmdUpdate.CommandText := 'UPDATE xx SET yy = :Param1 WHERE zz = :Param2';
  cmdUpdate.Parameters.ParamByName('Param2').Value := WhereClause;
  if VarIsNull(SetValue) then
  begin
    cmdUpdate.Parameters.ParamByName('Param1').DataType := ftString;
    cmdUpdate.Parameters.ParamByName('Param1').Size := 1;
  end else cmdUpdate.Parameters.ParamByName('Param1').Value := SetValue;
  cmdUpdate.Execute;
finally
  cmdUpdate.Free;
end;
0

I just ran into this error today on a TADOQuery which has ParamCheck := False and has no colons in the SQL.

Somehow passing the OLECMDEXECOPT_DODEFAULT parameter to TWebBrowser.ExecWB() was causing this for me:

This shows the problem:

pvaIn := EmptyParam;
pvaOut := EmptyParam;
TWebBrowser1.ExecWB(OLECMDID_COPY, OLECMDEXECOPT_DODEFAULT, pvaIn, pvaOut);

This does not show the problem:

pvaIn := EmptyParam;
pvaOut := EmptyParam;
TWebBrowser1.ExecWB(OLECMDID_COPY, OLECMDEXECOPT_DONTPROMPTUSER, pvaIn, pvaOut);
0

A single double quote in the query can also raise this error from what I just experienced and I am not using parameters at all ...

0

You can get this error when attempting to use a time value in the SQL and forget to wrap it with QuotedStr().

0

I got the same error. Turned out, that it is because a parameter of the stored procedure was declared as varchar(max). Made it varchar(4000) and error disappeared.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.