I'm looking for a tool or a method to reliably determine which SDF version a given file is implementing.

So far I've been using Autodesk's SDF Loader with the /info flag, but it only supports SDFv2.

Unfortunately I have a large number of SDF files of various version where i need determine which ones need to be upgraded to SDFv3. As FDO Toolbox only supports SDFv3 and we are upgrading from MapGuide 6.5 which only supports SDFv2.

So in summary I'm looking for a reliable way to determine the major and minor version number of the SDF file hopefully in a single tool. (I'm aware of FME, leaving it as a last resort due to cost)


When you try to connect to a SDF < 3.0 file with FDO, the SDF provider will throw an exception with a specific message (SDF file appears to be version 2.1 or older. Please convert to SDF version 3)

Therefore an ugly, but workable feasible solution is to employ the following logic in C#:

try {
    //Try to connect using FDO. If you can open/close without exceptions, it's a valid SDF3 file
} catch (OSGeo.FDO.Common.Exception ex) {
    if (ex.Message == "SDF file appears to be version 2.1 or older. Please convert to SDF version 3") {
        //Try using SDF loader. If you can open/close without errors, it's a valid SDFv2 file

In addition to what Jackie said:

Also from the FDO, you can somewhat just check the first few bytes of the SDF file. It's not a guaranteed, but should be pretty reliable, especially if you've only used one tool to create those SDF files. Perhaps this is easier, since it's pretty standalone (not depending on the FDO) and you can write this with pretty much any language.

From the FDO code:

//while we have the file open, check if it is
//an older SDF (2.1 or older) by reading the first few bytes.
//all this is done in little-endian.
unsigned long value;
fread(&value, sizeof(unsigned long), 1, f);

if((value & 0x0000ffff) == 0x00002c00)
    // 2.x versions
    // Might also include 1.0, but it is not
    //guaranteed to be old SDF since other binary files
    //can have the same initial bytes

    //Note that for SDF3 (SQLite) files, the first 4 DWORDS are:
    //value[0] == 0x00000000
    //value[1] == 0x00000001
    //value[2] == 0x00000000
    //value[3] == 0x00053162
    //But the correct way to check version from now on is to 
    //open the Schema database and read the version number, which
    //we do later in this function.

    throw ...

FDO v3.6.0: OpenSource_FDO/Providers/SDF/Src/Provider/SdfConnection.cpp line: 285


You can check the first bytes of the file. If they contain "SQLITE" you are dealing with v3.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.