Realtime COUNT field incorrect or syntax error

I am using realtime for my contactcenter and everything is fine except below warning in the log:

[May 13 01:23:19] WARNING[5341]: res_odbc.c:538 ast_odbc_print_errors: SQL Execute returned an error: 07002: [Microsoft][ODBC Driver 17 for SQL Server]COUNT field incorrect or syntax error
[May 13 01:23:19] WARNING[5341]: res_odbc.c:433 ast_odbc_prepare_and_execute: SQL Execute error -1!

I tried to trace odbc log and couldn’t find the root cause of warning. I tried to add count field into sip table and its also not fixed my issue.

The warning appears mainly when connecting or disconnecting sip users. I tried to play with fields and compared with many examples but cant find root cause.

COUNT is not a database field.

This appears to be the number of parameters provided for a parameterized SQL statement doesn’t match the number of parameter markers found in the template statement. Without knowing the actual call that failed, I’m not sure I can go any further:"COUNT-field-incorrect-or-syntax-error-(SQL-07002)"?

Very few people would use Asterisk with the Microsoft product.

Thanks a lot David, I tried to tracing queries and its coming like in below and I cant check what kind of data sending.
Tried also to passing varchar(180) its maximum length but anyway its not help.

Indeed, MsSQL is not a database that we really support. Any support for it has come from the community, so something may have changed or become broken since the last push for supporting it.

Yes indeed SQL Server is not proper way but we already developed CRM and many things related to SQL Server features. I tried to trace queries but unfortunately data is coming as variables.
Mainly error appears when executing this two query:

UPDATE _sips SET ipaddr=@P1, fullcontact=@P2, lastms=@P3, useragent=@P4, username=@P5, regseconds=@P6, port=@P7 WHERE name=@P8

UPDATE _sips SET lastms=@P1 WHERE name=@P2

Table structure:

id int
name nvarchar(80)
host varchar(80)
nat varchar(31)
type varchar(255)
accountcode varchar(255)
amaflags varchar(255)
[call-limit] varchar(255)
callgroup varchar(255)
callerid varchar(255)
cancallforward varchar(255)
canreinvite varchar(255)
context varchar(255)
defaultip varchar(255)
dtmfmode varchar(255)
fromuser varchar(255)
fromdomain varchar(255)
insecure varchar(255)
language varchar(255)
mailbox varchar(255)
md5secret varchar(255)
[deny] varchar(255)
permit varchar(255)
mask varchar(255)
musiconhold varchar(255)
pickupgroup varchar(255)
qualify varchar(255)
regexten varchar(255)
restrictcid varchar(255)
rtptimeout varchar(255)
rtpholdtimeout varchar(255)
secret varchar(255)
setvar varchar(255)
disallow varchar(255)
allow varchar(255)
fullcontact varchar(255)
ipaddr varchar(255)
port varchar(255)
regserver varchar(255)
regseconds varchar(255)
lastms varchar(255)
username varchar(255)
defaultuser varchar(255)
subscribecontext varchar(255)
useragent varchar(255)
callbackextension varchar(255)

I don’t think the table contact is relevant. You need to see the parameters to the, internal, function ast_update_realtime, and what it then calls. NB this function has a variable argument list.

The code should be setting up some sort of request structure, which includes the values for P1, P2…, and there is something wrong with that structure, that makes SQL Server think there are not 8 parameters in the first example, and not two in the second.

If you can reproduce this easily, you should build a debug version of Asterisk, and set a breakpoint on the line indicated in the error message. Unfortunately, the variable structures will mean that you won’t be able to see the fine details in a backtrace, and will need to, manually, decompose parameter lists and SQL requests.


Really appreciated with you kind of support. I`ll try to follow your recommendation and will comeback with summaries soon.


This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.