| Previous | Next |
| DB_E_BADCONSTRAINTTYPE | DB_E_BADDEFERRABILITY |
DB_E_BADCONSTRAINTFORM
ConstraintType is not DBCONSTRAINTTYPE_FOREIGNKEY and cForeignKeyColumns is not zero
Exact value and result class
DB_E_BADCONSTRAINTFORM has unsigned value 2147749496 (0x80040E78) and signed 32-bit value -2147217800. AllStat describes it as “ConstraintType is not DBCONSTRAINTTYPE_FOREIGNKEY and cForeignKeyColumns is not zero”. In this result, a DBCONSTRAINTDESC has a field combination inconsistent with its declared constraint type.
The high bit is set, so DB_E_BADCONSTRAINTFORM is a failure HRESULT. Its facility is 4 (FACILITY_ITF) and its low code is 3704 (0x0E78). For DB_E_BADCONSTRAINTFORM, these fields identify an interface-defined result family; they do not identify the provider instance, method, object generation or partial effects.
Evidence to collect
A useful DB_E_BADCONSTRAINTFORM event records provider CLSID and version, process architecture, interface IID and method, object correlation ID, transaction state and the immediately preceding HRESULT. When recording DB_E_BADCONSTRAINTFORM data involving catalog names, schema names, object identifiers and deployment definitions, use types, lengths, hashes or redacted identifiers rather than secrets or complete business data.
- Evidence 1 for
DB_E_BADCONSTRAINTFORM: constraint type and every count field. - Evidence 2 for
DB_E_BADCONSTRAINTFORM: presence of local and foreign key arrays. - Evidence 3 for
DB_E_BADCONSTRAINTFORM: provider validation status for the descriptor.
Contract boundary
For DB_E_BADCONSTRAINTFORM, OLE DB DDL interfaces identify indexes, commands and constraints with provider-scoped DBIDs. For DB_E_BADCONSTRAINTFORM, constraint descriptors also carry type, column arrays, match behavior, deferrability and update/delete rules that must agree as one structure.
Investigation of DB_E_BADCONSTRAINTFORM should start with the session performing DDL, target table metadata and the exact DBID or DBCONSTRAINTDESC supplied. Capture DB_E_BADCONSTRAINTFORM before ADO, ATL, .NET or a database abstraction layer replaces the native HRESULT with a generic exception.
Conditions that specifically lead to this result
- Cause 1 for
DB_E_BADCONSTRAINTFORM: foreign-key column fields are populated for a non-foreign-key constraint. - Cause 2 for
DB_E_BADCONSTRAINTFORM: required column arrays are missing for the chosen type. - Cause 3 for
DB_E_BADCONSTRAINTFORM: counts and pointers disagree within the descriptor.
Diagnostic sequence
- Capture raw
0x80040E78and symbolicDB_E_BADCONSTRAINTFORMat the native call boundary. - Identify the exact failing stage for
DB_E_BADCONSTRAINTFORM: a DBCONSTRAINTDESC has a field combination inconsistent with its declared constraint type. - Retrieve all OLE DB error records for
DB_E_BADCONSTRAINTFORMbefore another COM call replaces thread error information. - Compare the live object state and provider-granted capabilities with the input that produced
DB_E_BADCONSTRAINTFORM. - Reduce the
DB_E_BADCONSTRAINTFORMoperation to the smallest case that preserves the same ddl contract. - Apply one evidence-backed correction for
DB_E_BADCONSTRAINTFORMand verify that the result is not merely replaced by a neighboring HRESULT.
Corrective actions
- Action 1 for
DB_E_BADCONSTRAINTFORM: initialize descriptors by constraint type. - Action 2 for
DB_E_BADCONSTRAINTFORM: zero fields that do not apply. - Action 3 for
DB_E_BADCONSTRAINTFORM: validate count and pointer pairs before the DDL call.
Practical scenario
A UNIQUE constraint accidentally retains foreign-key column count from a reused structure; clearing irrelevant fields makes the form valid. Keeping DB_E_BADCONSTRAINTFORM with the method and object state makes this scenario diagnosable instead of reducing it to “database error”.
Developer and operations guidance
Code handling DB_E_BADCONSTRAINTFORM should release COM objects in ownership order, retain per-row, per-column or per-property statuses, and log granted capabilities rather than only requested options. While handling DB_E_BADCONSTRAINTFORM, opaque values such as HACCESSOR, HROW, HCHAPTER, DBID components and provider handles must remain scoped to the object that issued them.
Operational dashboards for DB_E_BADCONSTRAINTFORM should group by provider version, interface, method and normalized failure stage. A DB_E_BADCONSTRAINTFORM event must not expose passwords, tokens, full connection strings, unrestricted command text or raw row contents.
Retry and recovery
Retry rule for DB_E_BADCONSTRAINTFORM: retry after making the descriptor shape consistent with ConstraintType. A DB_E_BADCONSTRAINTFORM retry is safe only when the relevant input, object generation, capability or external state has changed. Before replaying a modifying call that returned DB_E_BADCONSTRAINTFORM, determine whether rows, schema objects or URL resources were partially created or changed.
Do not turn DB_E_BADCONSTRAINTFORM into an unbounded retry loop. Preserve cancellation for DB_E_BADCONSTRAINTFORM and use a fresh provider object when the failed call may have left local state ambiguous.
Difference from nearby HRESULT values
DB_E_BADCONSTRAINTTYPE rejects the enumeration, while DB_E_BADCONSTRAINTFORM rejects the structure built around a recognized type. Telemetry and remediation for DB_E_BADCONSTRAINTFORM should keep these outcomes distinct.
Official Microsoft references
- Microsoft: OLE DB data definition language — official documentation relevant to
DB_E_BADCONSTRAINTFORM. - Microsoft: ITableDefinitionWithConstraints — official documentation relevant to
DB_E_BADCONSTRAINTFORM. - Microsoft: IAlterTable::AlterTable — official documentation relevant to
DB_E_BADCONSTRAINTFORM.
Looking for a different code? Search another status or error code.