PHP Sybase – What Do These Error Messages Mean

freetdsPHPsybase

This is running on an AWS AMI EC2 Linux instance in a PHP script using dblib and PDO to connect to remote Sybase databases (Sybase version 11.0.1.2596). The server has freetds with these settings:

Compile-time settings (established with the "configure" script)
                        Version: freetds v0.91
         freetds.conf directory: /etc
 MS db-lib source compatibility: yes
    Sybase binary compatibility: yes
                  Thread safety: yes
                  iconv library: yes
                    TDS version: 4.2
                          iODBC: no
                       unixodbc: yes
          SSPI "trusted" logins: no
                       Kerberos: yes

Sometimes when we run queries on the sybase computers we get an error like this (the token can vary):

TDS: unexpected token 95 [0] (severity 0) [(null)]

The query sometimes runs even after this error and sometimes fails. I have searched online but I can't find what this error means or how to fix it. Here is an example of one of the queries:

-- 999 | Hammil | 2017-04-05 08:23:29 
SELECT  
    999 as 'site_id',
    (select rest_name from micros.rest_def) as 'location',
    now() as 'dt_run',
    emp_seq,
    employee_number as 'obj_num',
    last_name,
    first_name,
    check_number,
    xfer_from_check,
    xfer_from_type,
    xfer_to_check,
    xfer_to_type,
    check_id,
    table_number,
    table_name,
    group_number,
    cover_count,
    order_type,
    order_type_name,
    business_date,
    check_open_date_time,
    check_closed_date_time,
    table_open_date_time,
    printed_count,
    sub_ttl,
    tax_ttl,
    auto_svc_ttl,
    other_svc_ttl,
    paymnt_ttl,
    amount_due_ttl,
    sp_error
FROM
    micros.micros.v_R_guest_checks x
where
    x.check_closed_date_time is null;

Sometimes we get this error:

SQLSTATE[HY000]: General error: 20047 DBPROCESS is dead or not enabled [20047] (severity 1) [(null)]

When this happens, I can run

nc -v -w 4 xxx.xxx.xxx.xxx 2638

and it returns

Connection to xxx.xxx.xxx.xxx 2638 port [tcp/sybaseanywhere] succeeded!

but I will continue to get the error for a few minutes and then it goes away.

Best Answer

An unexpected token in TDS indicates a bad network packet was sent to the TCP Port Sybase is listening to.

This indicates one of two things:

  1. an intermittent network connectivity problem where TCP TDS packets are being corrupted
  2. you have some process attempting to connect to the Sybase instance without using TDS.

I've seen #2 happen with security scanning processes that are looking for open ports.

From your symptoms it sounds like a network connectivity issue. Since the Sybase Anywhere server is not on the same network segment as your client machine, I'd tend to think the client needs to gracefully handle connectivity problems.