5

I would like to import my File Geodatabase from ArcGIS 10.1 into MS SQL Server 2012.

I have never done it before, so I expect to do the import the same way as import data from excel table.

Problem is when I open MS SQL Server Import wizard and as a data source I choose Esri geodatabse OLE DB provider - an error occured:

ClassFactory cannot get required class. (Microsoft OLE DB Service Components)

Please does anybody know what I´m doing wrong, or is there some easiest way, for example with ArcSDE?

1
  • Isn't is so that shapefiles do not contain topology (for example the relation between two connecting line objects in a road layer), meaning you will loose this information if you first convert to a shapefile?
    – user30902
    Commented Jun 2, 2014 at 13:49

3 Answers 3

4

ArcSDE is the best option to Import and Manage your Geodatabase in Database servers ( SQL server,Oracle ,...) . You can't import File Geodatabase or Personal Geodatabase directly in SQL server . you should use ArcSDE software . The Geodatabase type of ArcSDE is SDE Geodatabase not File Geodatabse. I think you should use ArcSDE to Import And Manage your Geodatabase. Don't doubt to change of Geodatabase type from File to SDE Geodatabase. maybe you'd like to use Permissions,Versioning,History,syncronizing and another capabilities of SDE Geodatabase.

1
  • Does this imply that you are merely pointing to an SDE feature class then converting it to SQL server spatial data type? Couldn't you also convert to shapefile and use the Shp2SQL import tool? Commented Jun 3, 2013 at 18:51
2

If you do have access to ArcSDE, then all of your conversion can be done within the ArcGIS Desktop/Arcpy kit of tools. For example, in ArcCatalog you simply right-click the feature class in your file GDB and select Export/Geodatabase (single or multiple items).

If you are not afraid of scripting, I would recommend pyodbc. You can use a da.SearchCursor to create an array of values using the SHAPE@WKT field option so your geometry is in WKT. This can be loaded into a temporary table in Sql Server as VARCHAR(MAX) which can then be loaded into your Sql Server table with a Geometry column.

This is a very brief arcpy sample and will not run on its own:

import arcpy, os, pyodbc
# a shapefile
par = (r'[your shapefile/gdb feature class path]')
# fields you want to include
fields = ['FID',[other fields...,] 'SHAPE@WKT']
# a query to limit records; useful for testing
qry = (r'FID < 100000')

# pyodbc connection to sql server 2012
cnxn = pyodbc.connect('driver={SQL Server Native Client 11.0};server=[server];'
                      'database=[dbname];Trusted_Connection=YES')
# define a cursor object
cursor = cnxn.cursor()
# create table query - #tmpPar is a temporary table
ctQry = ("""
Create Table #tmpPar (OID Int Not Null,[other fields...,] SHAPE Varchar(Max) NULL)
;""")

# create the temp table
cursor.execute(ctQry)
cnxn.commit()

# insert query; ? are parameter placeholders
itQry = ("""
Insert Into #tmpPar (OID,[fields...,]Shape)
Values (?,?,?);""")
# Query to Insert records from temp table into sql table
ipQry = ("""
Insert into [tablename] (ObjectId, [fields...,] Shape)
(Select OID, [fields...,] Shape From #tmpPar);""")

# use the search cursor of the shapefile to insert
# records into the temp table
rows = arcpy.da.SearchCursor(par,fields,qry)
for row in rows:
  cursor.execute(itQry, row[0], row[1], row[2])
  cnxn.commit()

# insert recs from tmpPar to sql server table
cursor.execute(ipQry)
cnxn.commit()

I see this question is a bit dated but perhaps someone else who is struggling with an approach will stumble on this and save some time.

1

You could also go via shape file (not the most elegant but gets the job done): FileGeodatabase -> Export to ShapeFile - then use Shape2SQL tool to import shape into Sql Server.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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