PowerBuilder · Database exception

SQLSTATE 22005 (Invalid Character Value for Cast)

What does SQLSTATE 22005 (Invalid Character Value for Cast) mean in PowerBuilder?

A DataWindow retrieve against SQL Server fails with SQLSTATE 22005, 'invalid character value for cast specification,' when a column defined in the DataWindow is too narrow to hold the data a stored procedure or query actually returns for it, so the ODBC/native driver rejects the cast during the fetch. It can appear only after a PowerBuilder version upgrade if the newer client library enforces stricter type/length checking than the previous one did.

SQLSTATE 22005 (Invalid Character Value for Cast)PowerBuilder Classic · Appeon PowerBuilder

Condition

A DataWindow retrieve against SQL Server fails with SQLSTATE 22005, 'invalid character value for cast specification,' when a column defined in the DataWindow is too narrow to hold the data a stored procedure or query actually returns for it, so the ODBC/native driver rejects the cast during the fetch. It can appear only after a PowerBuilder version upgrade if the newer client library enforces stricter type/length checking than the previous one did.

Fix

Widen the mismatched DataWindow column definitions to match the actual returned column sizes rather than the assumed schema, and re-sync the DataWindow's SQL/column metadata after any stored procedure signature change. If the error appears only after upgrading PowerBuilder, check whether new DBParm settings (e.g. stricter parameter/name stripping options) need to be added for parity with the old client behavior.

Related database exception