MATLAB Answers

MATLAB 2017a Database Toolbox update.m producing 'COUNT field incorrect '

4 views (last 30 days)
Joshua M. Wilson
Joshua M. Wilson on 2 May 2017
Answered: Bruce on 20 Nov 2017
Since upgrading from MATLAB 2016a (64-bit) to MATLAB 2017a (64-bit) on Windows 2008 R2 server, updating records in an Access 2016 database no longer works. I connect to the Access database, an ODBC system file, using database(). I can run the same scripts in the 2016a environment and the update is successful. When I compare the update.m scripts that are called by MATLAB, they are very different ([path] is simply the system disk and directory):
2016a: [path]\Program Files\MATLAB\R2016a\toolbox\database\database\@database\update.m
2017a: [path]\Program Files\MATLAB\R2017a\toolbox\database\database\+database\+odbc\@connection\update.m
The error message is:
message: 'ODBC Driver Error: [Microsoft][ODBC Microsoft Access Driver]COUNT field incorrect '
stack.file: '[path]\Program Files\MATLAB\R2017a\toolbox\database\database\+database\+odbc\@connection\update.m'
stack.line: 301
I've searched other boards on this ODBC error and tried some advice found there (i.e., verifying a field name isn't an SQL Keyword).
I am able to insert new records (fastinsert, datainsert), but can NOT update records.

  1 Comment

Joshua M. Wilson
Joshua M. Wilson on 5 May 2017
FYI for those who come across this question, this was subsequently submitted as a Bug Report (Technical Support Case #02557133). The initial response I received from Technical Support was, in essence: "I was able to replicate the issue on my end using a sample Access database, and I am currently investigating the issue." I received some workaround suggestions, but a solution is apparently pending as of today.

Sign in to comment.

Accepted Answer

Kevin Gleason
Kevin Gleason on 5 May 2017
The issue that you are facing is caused due to removal of JDBC-ODBC bridge connector starting MATLAB R2017a. If you are creating a database connection using the following syntax, it uses the JDBC-ODBC connector (in R2016b and earlier versions):
>> conn = database(instance,username,password)
However, starting MATLAB R2017a, the database connection that is created uses Native ODBC driver (Native ODBC driver is used if "database.ODBC" command is used, for R2016b and earlier versions) and the error that is occurring is being thrown by the Access ODBC driver when a VARCHAR column is created without specifying length
We have two workarounds for the issue:
1. Alter the table and specify the lengths for the columns that are of VARCHAR type.
For instance, if you have a table (Table1) that is having a column called Age which is of VARCHAR type originally, you can specify the length using the following command:
>> exec(conn,'ALTER TABLE Table1 Alter Column Age varchar(30)') %30 can be any other value
After altering the table the update command should work correctly.
2. Use the "exec" function with a SQL query string.
>> query = 'update MyTable SET Value = 10 where ID = 2';
>> exec(conn, query);
(Note: this is from your active support case, continue working with your TS representative.)

  0 Comments

Sign in to comment.

More Answers (1)

Bruce
Bruce on 20 Nov 2017
Is this fixed in 2017b? If not, will it be fixed in a future release?

  0 Comments

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by