how to convert mdb to gdb

17687
8
Jump to solution
04-05-2018 04:41 AM
santhoshp
Occasional Contributor

Dear Friends,

Attached here multiple mdb. How to convert multiple mdb to multiple gdb with data name wise at a time all mdb's any python code available please help me.

Thanks

Santhosh

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
XanderBakker
Esri Esteemed Contributor

That importing feature class (multiple) will not take care of your related tables and relationshipclasses. The Copy—Help | ArcGIS Desktop tool is more equipped for this purpose.

Here is some code that should do the job.

Change:

  • input MDB folder and output FGDB folder on line 6 and 

def main():
    import arcpy
    import os

    # input and output folders
    folder_mdb = r'C:\GeoNet\mdb2gdb\test\pgdb'  # input folder
    folder_gdb = r'C:\GeoNet\mdb2gdb\test\fgdb3'  # output folder

    # set workspace to mdb folder and lst personal gdb's
    arcpy.env.workspace = folder_mdb
    pgdbs = arcpy.ListWorkspaces(workspace_type="Access")

    # loop through personal gdb's
    for pgdb in pgdbs:
        # create output empty output fgdb
        mdb_name = os.path.split(pgdb)[1]
        gdb_name = os.path.splitext(mdb_name)[0] + ".gdb"

        fgdb = os.path.join(folder_gdb, gdb_name)
        print("Create FGDB: {}".format(fgdb))
        arcpy.CreateFileGDB_management(folder_gdb, gdb_name, "CURRENT")

        # list feature datasets
        arcpy.env.workspace = pgdb
        fdss = arcpy.ListDatasets()
        fdss.append('')

        # loop through feature datasets to ceate list of RC's
        lst_rc = []
        for fds_name in fdss:
            print(" - Processing FDS: {}".format(fds_name))
            if fds_name != '':
                # create fds
                fds_mdb = os.path.join(pgdb, fds_name)
                sr = arcpy.Describe(fds_mdb).spatialReference
                arcpy.CreateFeatureDataset_management(fgdb, fds_name, sr)

                fcs = arcpy.ListFeatureClasses('*', None, fds_name)
                for fc_name in fcs:
                    fc_mdb = os.path.join(pgdb, fds_name, fc_name)
                    fc_gdb = os.path.join(fgdb, fds_name, fc_name)

                    # detect relationshipclasses
                    rc_names = arcpy.Describe(fc_mdb).relationshipClassNames
                    if len(rc_names) > 0:
                        for rc_name in rc_names:
                            print "    - rc_name:", rc_name
                            rc_mdb = os.path.join(pgdb, fds_name, rc_name)
                            rc_gdb = os.path.join(fgdb, fds_name, rc_name)
                        lst_rc.append([rc_mdb, rc_gdb])


        # copy relationship classes
        print(" - Copy Relationshipclasses")
        for rc in lst_rc:
            rc_mdb = rc[0]
            rc_name = os.path.split(rc_mdb)[1]
            rc_gdb = rc[1]
            print("   - Copy RC: {}".format(rc_name))
            arcpy.Copy_management(rc_mdb, rc_gdb)

        # copy featureclasses (that do not exist yet)
        print(" - Copy Featureclasses")
        for fds_name in fdss:
            print(" - Processing FDS: {}".format(fds_name))
            if fds_name != '':
                # create fds
                fds_mdb = os.path.join(pgdb, fds_name)
                sr = arcpy.Describe(fds_mdb).spatialReference

                fcs = arcpy.ListFeatureClasses('*', None, fds_name)
                for fc_name in fcs:
                    fc_mdb = os.path.join(pgdb, fds_name, fc_name)
                    fc_gdb = os.path.join(fgdb, fds_name, fc_name)
                    if arcpy.Exists(fc_gdb) == False:
                        print("   - Copy FC: {}".format(fc_name))
                        arcpy.Copy_management(fc_mdb, fc_gdb)

        # copy stand alone tables
        print(" - Copy Standalone tables")
        tbls = arcpy.ListTables()
        for tbl_name in tbls:
            tbl_mdb = os.path.join(pgdb, tbl_name)
            tbl_gdb = os.path.join(fgdb, tbl_name)
            if arcpy.Exists(tbl_gdb) == False:
                print("   - Copy TBL: {}".format(tbl_name))
                arcpy.Copy_management(tbl_mdb, tbl_gdb)


if __name__ == '__main__':
    main()

Relationshipclasses will be copied to the Feature Dataset of the Featureclass where the RC was detected. They are not copied to the root where the RC's are stored in the input MDB.

View solution in original post

8 Replies
shan_sarkar
Occasional Contributor III

Santosh,

Are you trying to bring all the mdb's into a single gdb?

~Shan


~Shan
santhoshp
Occasional Contributor

Hi Sarkar,

No, I want individual gdb's.

Thanks

Santhosh

0 Kudos
shan_sarkar
Occasional Contributor III

Santosh,

Check Importing a feature class (multiple)—ArcGIS Help | ArcGIS Desktop 

You can execute this tool with the batch option.

~Shan


~Shan
0 Kudos
XanderBakker
Esri Esteemed Contributor

That importing feature class (multiple) will not take care of your related tables and relationshipclasses. The Copy—Help | ArcGIS Desktop tool is more equipped for this purpose.

Here is some code that should do the job.

Change:

  • input MDB folder and output FGDB folder on line 6 and 

def main():
    import arcpy
    import os

    # input and output folders
    folder_mdb = r'C:\GeoNet\mdb2gdb\test\pgdb'  # input folder
    folder_gdb = r'C:\GeoNet\mdb2gdb\test\fgdb3'  # output folder

    # set workspace to mdb folder and lst personal gdb's
    arcpy.env.workspace = folder_mdb
    pgdbs = arcpy.ListWorkspaces(workspace_type="Access")

    # loop through personal gdb's
    for pgdb in pgdbs:
        # create output empty output fgdb
        mdb_name = os.path.split(pgdb)[1]
        gdb_name = os.path.splitext(mdb_name)[0] + ".gdb"

        fgdb = os.path.join(folder_gdb, gdb_name)
        print("Create FGDB: {}".format(fgdb))
        arcpy.CreateFileGDB_management(folder_gdb, gdb_name, "CURRENT")

        # list feature datasets
        arcpy.env.workspace = pgdb
        fdss = arcpy.ListDatasets()
        fdss.append('')

        # loop through feature datasets to ceate list of RC's
        lst_rc = []
        for fds_name in fdss:
            print(" - Processing FDS: {}".format(fds_name))
            if fds_name != '':
                # create fds
                fds_mdb = os.path.join(pgdb, fds_name)
                sr = arcpy.Describe(fds_mdb).spatialReference
                arcpy.CreateFeatureDataset_management(fgdb, fds_name, sr)

                fcs = arcpy.ListFeatureClasses('*', None, fds_name)
                for fc_name in fcs:
                    fc_mdb = os.path.join(pgdb, fds_name, fc_name)
                    fc_gdb = os.path.join(fgdb, fds_name, fc_name)

                    # detect relationshipclasses
                    rc_names = arcpy.Describe(fc_mdb).relationshipClassNames
                    if len(rc_names) > 0:
                        for rc_name in rc_names:
                            print "    - rc_name:", rc_name
                            rc_mdb = os.path.join(pgdb, fds_name, rc_name)
                            rc_gdb = os.path.join(fgdb, fds_name, rc_name)
                        lst_rc.append([rc_mdb, rc_gdb])


        # copy relationship classes
        print(" - Copy Relationshipclasses")
        for rc in lst_rc:
            rc_mdb = rc[0]
            rc_name = os.path.split(rc_mdb)[1]
            rc_gdb = rc[1]
            print("   - Copy RC: {}".format(rc_name))
            arcpy.Copy_management(rc_mdb, rc_gdb)

        # copy featureclasses (that do not exist yet)
        print(" - Copy Featureclasses")
        for fds_name in fdss:
            print(" - Processing FDS: {}".format(fds_name))
            if fds_name != '':
                # create fds
                fds_mdb = os.path.join(pgdb, fds_name)
                sr = arcpy.Describe(fds_mdb).spatialReference

                fcs = arcpy.ListFeatureClasses('*', None, fds_name)
                for fc_name in fcs:
                    fc_mdb = os.path.join(pgdb, fds_name, fc_name)
                    fc_gdb = os.path.join(fgdb, fds_name, fc_name)
                    if arcpy.Exists(fc_gdb) == False:
                        print("   - Copy FC: {}".format(fc_name))
                        arcpy.Copy_management(fc_mdb, fc_gdb)

        # copy stand alone tables
        print(" - Copy Standalone tables")
        tbls = arcpy.ListTables()
        for tbl_name in tbls:
            tbl_mdb = os.path.join(pgdb, tbl_name)
            tbl_gdb = os.path.join(fgdb, tbl_name)
            if arcpy.Exists(tbl_gdb) == False:
                print("   - Copy TBL: {}".format(tbl_name))
                arcpy.Copy_management(tbl_mdb, tbl_gdb)


if __name__ == '__main__':
    main()

Relationshipclasses will be copied to the Feature Dataset of the Featureclass where the RC was detected. They are not copied to the root where the RC's are stored in the input MDB.

RobertBorchert
Frequent Contributor III

Really too much work.

Simply select your Features or Feature data sets in one and copy them to the other.

We do this all the time for our items that are used for our Online presence.

0 Kudos
santhoshp
Occasional Contributor

Hi Xander Bakker,

Thank You so much.

Thanks

Santhosh

0 Kudos
XanderBakker
Esri Esteemed Contributor

There is some code provided here: arcgis desktop - Copying feature classes from Personal Geodatabase to File Geodatabase using ArcPy? ...  however, your geodatabases contain tables, relationshipclass and domains and I doubt if these will be transferred too. Due to the relationshipclasses you will need to use a Standard or Advanced licence to run the code.

Is it that you have many personal geodatabases or are these the only ones? If these are all, it is much faster to copy and paste the content of the personal geodatabase to a file geodatabase.

RobertBorchert
Frequent Contributor III

Lots of over thinking here.

Simply use ArcCatalog. Create your new FileGeodatabases and then copy and paste your feature datasets into the new data base.

If you have a lot of DB's (by a lot I mean more than 30) there are other ways. I once combined 1400 filegeodatabases into a single Personal Geodatabase using a complicated python script that I built using Model Builder and MS Access.

0 Kudos