Trying to use Ucanaccess with Java 8 to connect to Access 2002-2003 based .MDB database.
I get hit with the below error:
java.lang.IllegalStateException: Could not determine FileFormat (Db=XXX.mdb)
This db was created programatically.
I have tried creating a DB (.MDB) using Access 2013 and saved the DB file as Access 2002-2003, and tried to connect gets the below exception:
Exception string: java.lang.StringIndexOutOfBoundsException: String index out of range: -1
Any timely helps is greatly appreciated.
Thanks
Venky
Last edit: Venkata Swamy Karukuri 2015-11-15
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
When you say that "This db was created programatically" do you mean that it was created by UCanAccess, or created by some other application? Can you open your original .mdb file in Access itself?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The error is from Jackcess, trace is below:
java.lang.IllegalStateException: Could not determine FileFormat (Db=WGN.mdb)
at com.healthmarketscience.jackcess.impl.DatabaseImpl.getFileFormat(DatabaseImpl.java:741)
at net.ucanaccess.jdbc.UcanaccessDatabaseMetadata.getDatabaseProductVersion(UcanaccessDatabaseMetadata.java:482)
at myprod.schema.SQLScriptParser.DetermineProductVersion(SQLScriptParser.java:1261)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Ok, so it's a known issue. In some cases, jackcess can't determine FileFormat and ucanaccess catches this exception when is establishing the connection. But you're invoking getDatabase ProductVersion directly and ucanaccess can't do something different than re-throwing the exception. As Gord said, try doing a Compact and Repair Database may solve. Or contact the jackcess team.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I could reproduce the issue with sample Java application and the DB that was created using ADOX API.
When I open the ADO created .mdb file, i could reproduce the issue, but when I open and close the same DB using Access, and then try to use it, able to connect and fetch product version successfully.
DatabaseImpl.class of jackcess with
propsBytes = objectRow.getBytes(CAT_COL_PROPS);
is returning 'null' in failure case.
Connection string using to create DB is:
_T("Provider=Microsoft.JET.OLEDB.4.0; Data source=%s.mdb;"\
"Jet OLEDB:System Database=%s.mdw;"\
"User ID=Admin; Password=");
In fact we use Database.getFormat(), whose implementation throws the exception above because the format is null.
Can't see another related method in the exposed Database interface.
Last edit: Marco Amadei 2015-11-16
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I have opened a Jackcess ticket here. In the meantime you could trap the error and work around it since it appears that Jackcess (and UCanAccess) can read the file okay, it's just the Database#getFileFormat() call in Jackcess that's failing.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
It's an option. Notice I already trap it anywhere, except for the getDatabaseProductVersion() DatabaseMetadata method where I wanted that the Exception goes up. But I may change opinion because I didn't know the database programmatic creation is a possible root cause. It is not an abnormal condition, so an exception isn't actually justified. In other words, I think I'll do it (but returning a null might cause a null pointer exception in the client side and a misleading issue as well)
Last edit: Marco Amadei 2015-11-16
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi Marco. When I said "you could trap the error and work around it" my comment was really directed at the OP. You might want to wait for a response from Jackcess before considering a change to UCanAccess.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Were you able to find any fixes for the problem?
Although we could connect to DB without fetching Product Version, I have some dependency activities based on DB version.
I am thinking if I could live with the failure and provide work around in my application or is it worth waiting for the fix to come in.
Thank you both the kind responses.
Venky
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
In some layer a workaround is needed. You can assume that if an exception is thrown you'll never be able to get the version, even if we fix. So if you catch the exception in your application communicating, just in this case, that the version is not available, whereas in the mainstream you get the version number, you've finished.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi,
Trying to use Ucanaccess with Java 8 to connect to Access 2002-2003 based .MDB database.
I get hit with the below error:
java.lang.IllegalStateException: Could not determine FileFormat (Db=XXX.mdb)
This db was created programatically.
I have tried creating a DB (.MDB) using Access 2013 and saved the DB file as Access 2002-2003, and tried to connect gets the below exception:
Exception string: java.lang.StringIndexOutOfBoundsException: String index out of range: -1
Any timely helps is greatly appreciated.
Thanks
Venky
Last edit: Venkata Swamy Karukuri 2015-11-15
When you say that "This db was created programatically" do you mean that it was created by UCanAccess, or created by some other application? Can you open your original .mdb file in Access itself?
The .mdb database was created using Micorosoft ADO DB API, and yes, I could open, view the .mdb in MS Access.
Try doing a Compact and Repair Database operation in Access to see if that helps.
And anyway, this exception doesn't come from ucanaccess directly, so a full stacktrace (along the ucanaccess version you're using) may be useful.
Using - ucanaccess-3.0.2
-jackcess-2.1.2.jar
The error is from Jackcess, trace is below:
java.lang.IllegalStateException: Could not determine FileFormat (Db=WGN.mdb)
at com.healthmarketscience.jackcess.impl.DatabaseImpl.getFileFormat(DatabaseImpl.java:741)
at net.ucanaccess.jdbc.UcanaccessDatabaseMetadata.getDatabaseProductVersion(UcanaccessDatabaseMetadata.java:482)
at myprod.schema.SQLScriptParser.DetermineProductVersion(SQLScriptParser.java:1261)
Ok, so it's a known issue. In some cases, jackcess can't determine FileFormat and ucanaccess catches this exception when is establishing the connection. But you're invoking getDatabase ProductVersion directly and ucanaccess can't do something different than re-throwing the exception. As Gord said, try doing a Compact and Repair Database may solve. Or contact the jackcess team.
I could reproduce the issue with sample Java application and the DB that was created using ADOX API.
When I open the ADO created .mdb file, i could reproduce the issue, but when I open and close the same DB using Access, and then try to use it, able to connect and fetch product version successfully.
DatabaseImpl.class of jackcess with
propsBytes = objectRow.getBytes(CAT_COL_PROPS);
is returning 'null' in failure case.
Connection string using to create DB is:
_T("Provider=Microsoft.JET.OLEDB.4.0; Data source=%s.mdb;"\ "Jet OLEDB:System Database=%s.mdw;"\ "User ID=Admin; Password=");
Last edit: Venkata Swamy Karukuri 2015-11-16
In fact we use Database.getFormat(), whose implementation throws the exception above because the format is null.
Can't see another related method in the exposed Database interface.
Last edit: Marco Amadei 2015-11-16
I have opened a Jackcess ticket here. In the meantime you could trap the error and work around it since it appears that Jackcess (and UCanAccess) can read the file okay, it's just the Database#getFileFormat() call in Jackcess that's failing.
It's an option. Notice I already trap it anywhere, except for the getDatabaseProductVersion() DatabaseMetadata method where I wanted that the Exception goes up. But I may change opinion because I didn't know the database programmatic creation is a possible root cause. It is not an abnormal condition, so an exception isn't actually justified. In other words, I think I'll do it (but returning a null might cause a null pointer exception in the client side and a misleading issue as well)
Last edit: Marco Amadei 2015-11-16
Hi Marco. When I said "you could trap the error and work around it" my comment was really directed at the OP. You might want to wait for a response from Jackcess before considering a change to UCanAccess.
Yes, I misunderstood, I'm less receptive when I'm doing slides ;-)
Last edit: Marco Amadei 2015-11-16
Hi Marco or Thompson,
Were you able to find any fixes for the problem?
Although we could connect to DB without fetching Product Version, I have some dependency activities based on DB version.
I am thinking if I could live with the failure and provide work around in my application or is it worth waiting for the fix to come in.
Thank you both the kind responses.
Venky
In some layer a workaround is needed. You can assume that if an exception is thrown you'll never be able to get the version, even if we fix. So if you catch the exception in your application communicating, just in this case, that the version is not available, whereas in the mainstream you get the version number, you've finished.
This issue was fixed in UCanAccess courtesy of an upstream fix in Jackcess (v2.1.3).