Wednesday, October 15, 2008

Zinc Crashes on Select from Database

Background

I'm using Zinc 3 as a wrapper around a Flash 9 / ActionScript 3 application for a touch-screen kiosk that requires database and comport access.

Problem

The Zinc application crashes when calling mdm.Database.ADO.getData() to obtain the results of a query (either SELECT or stored procedure) executed by mdm.Database.ADO.select() IF the query produces an empty result set. I'm connecting to a MS SQL Server 2005 database, but this issue probably happens with any ADO connection.

Example
mdm.Database.ADO.select(sql); //if this results in 0 records...

if (mdm.Database.ADO.error())
   throw("handle error here");
else
   arr = mdm.Database.ADO.getData(); //crashes here

Solution

The undocumented but simple way to prevent the crash is: prior to calling getData(), you must first check ensure that getRecordCount() is not zero.

Example
mdm.Database.ADO.select(sql);

if (mdm.Database.ADO.error())
   throw("handle error here");
else if (mdm.Database.ADO.getRecordCount() == 0)
   arr = [];

else
   arr = mdm.Database.ADO.getData();

Conclusion

Ideally Zinc would just return an empty array if no records were found, but since it doesn't, it's nice to know there is an easy fix. I am content with minor problems like this because the benefits Zinc offers - including access to databases and the comport directly from Actionscript - far outweighs the bugs it has.

1 comment:

  1. hello, i have problem with connecting zinc 3 to MS SQL EXPRESS database. Can you post a little example how to connect zinc and sql server?

    ReplyDelete

Was this post helpful? Do you have questions about it? Do you want to share your own programming blog? I'd love to read your feedback.

Note: Only a member of this blog may post a comment.