Menu

java.lang.IllegalStateException: Could not determine FileFormat (Db=Mydb.mdb)

Help
2015-11-12
2015-11-19
  • Venkata Swamy Karukuri

    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
    • Gord Thompson

      Gord Thompson - 2015-11-12

      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?

       
  • Venkata Swamy Karukuri

    The .mdb database was created using Micorosoft ADO DB API, and yes, I could open, view the .mdb in MS Access.

     
    • Gord Thompson

      Gord Thompson - 2015-11-15

      Try doing a Compact and Repair Database operation in Access to see if that helps.

       
  • Marco Amadei

    Marco Amadei - 2015-11-15

    And anyway, this exception doesn't come from ucanaccess directly, so a full stacktrace (along the ucanaccess version you're using) may be useful.

     
  • Venkata Swamy Karukuri

    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)

     
  • Marco Amadei

    Marco Amadei - 2015-11-16

    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.

     
  • Venkata Swamy Karukuri

    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=");

    Using ADO API as below:
    ADODB::_ConnectionPtr m_pConn = NULL;
    
    _CatalogPtr pCatalog = NULL;
    TESTHR(m_pConn.CreateInstance(__uuidof(ADODB::Connection)));
    
    TESTHR(pCatalog.CreateInstance(__uuidof(Catalog)));
    pCatalog->Create( syscnn )
    
    --Attached DB.MDB with failure to fetch product version.
    
     

    Last edit: Venkata Swamy Karukuri 2015-11-16
  • Marco Amadei

    Marco Amadei - 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
  • Gord Thompson

    Gord Thompson - 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.

     
  • Marco Amadei

    Marco Amadei - 2015-11-16

    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
    • Gord Thompson

      Gord Thompson - 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.

       
  • Marco Amadei

    Marco Amadei - 2015-11-16

    Yes, I misunderstood, I'm less receptive when I'm doing slides ;-)

     

    Last edit: Marco Amadei 2015-11-16
  • Venkata Swamy Karukuri

    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

     
  • Marco Amadei

    Marco Amadei - 2015-11-19

    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.

     
  • Gord Thompson

    Gord Thompson - 2017-04-30

    This issue was fixed in UCanAccess courtesy of an upstream fix in Jackcess (v2.1.3).

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.