SQL Direct Execute Fail - ODBC Voicemail Not Written to DB

Seeing an occasional issue which manifests itself as a voicemail to email notification being sent, but the voicemail itself not being written to the database. Here’s the debug I see when this happens:

[2012-10-22 07:20:11] WARNING[21223] app_voicemail.c: SQL Direct Execute failed!
[2012-10-22 07:20:11] WARNING[21223] res_odbc.c: SQL Execute error! Verifying connection to fc_config [MySQL-Asterisk]…
[2012-10-22 07:20:11] WARNING[21223] res_odbc.c: Connection is down attempting to reconnect…
[2012-10-22 07:20:11] NOTICE[21223] res_odbc.c: Connecting fc_config
[2012-10-22 07:20:11] NOTICE[21223] res_odbc.c: res_odbc: Connected to fc_config [MySQL-Asterisk]
[2012-10-22 07:20:11] WARNING[21223] app_voicemail.c: SQL Direct Execute failed!
[2012-10-22 07:20:11] WARNING[21223] res_odbc.c: Connection is down attempting to reconnect…
[2012-10-22 07:20:11] NOTICE[21223] res_odbc.c: Connecting fc_config
[2012-10-22 07:20:11] NOTICE[21223] res_odbc.c: res_odbc: Connected to fc_config [MySQL-Asterisk]
[2012-10-22 07:20:11] WARNING[21223] app_voicemail.c: SQL Execute error!
[INSERT INTO voicemail_messages (dir,msgnum,recording,context,macrocontext,callerid,origtime,duration,mailboxuser,mailboxcontext,flag) VALUES (?,?,?,?,?,?,?,?,?,?,?)]

I have a few tasks for optimizing database access, but the underlying code here seems really brittle. Anyone dealt with this or worked through a better solution to how to manage this?

Still a bit of an issue here with flow and connection staleness, but to help others out, you might also check the “max_allowed_packet” size in MySQL. If sending uncompressed as BLOB, you may run into an issue with file size.