How to import a file geodatabase to SQL Server using a Python Script?

5477
7
07-23-2017 08:15 AM
deleted-user-qRkMX6AKcIjf
New Contributor II

How to import a file geodatabase to SQL Server using a Python Script? Are there any limitations? Which modules can I use to create a python script? Is pyodbc module the most appropriate one? Anyone has already any examples to show? thks, M.

0 Kudos
7 Replies
JoeFlannery
Regular Contributor II

Manuela:

Have you considered arcpy and the Feature Class to Feature Class command?

Here is a code sample:

http://pro.arcgis.com/en/pro-app/tool-reference/conversion/feature-class-to-feature-class.htm#C_GUID...

deleted-user-qRkMX6AKcIjf
New Contributor II

I did Joe. But I am looking to import the full file geodatabase in one go rather than exporting each feature class..

0 Kudos
XanderBakker
Esri Esteemed Contributor

There are some options mentioned here (although it is the other way around it will work for your case too): Copy a list of feature classes from Enterprise to Geodatabase 

shan_sarkar
Regular Contributor

Manuela,

You can simply use the same code mentioned in the help for Feature Class To Geodatabase—Help | ArcGIS Desktop. This should easily create all you feature classes in your target database with the same names. In case you have some non-spatial tables that also need to be moved in your target database you can use Table To Geodatabase—Help | ArcGIS Desktop 

Just keep in mind that you will have to add the an environment setting for the if you are using any. Refer What are configuration keywords?—ArcGIS Help | ArcGIS Desktop 

I hope this helps!

~Shan


~Shan
RebeccaStrauch__GISP
MVP Esteemed Contributor

If this is a one time deal, and you don't need it to be a Python script, you can do a copy-paste (using OS commands like control-c, control-v) into a Sde geodatabase.  The geodatabase would have to exist first, and you my want to copy datasets one at a time, not that it will not work all at once, but you have a bit more control knowing what has completed.

if for a class or will be repeated, I agree that feature classe to featureclass as mentioned above would be you best option.

deleted-user-qRkMX6AKcIjf
New Contributor II

HI Rebecca, it is not a one time deal. It should be automated a recorrer every month.

0 Kudos
shan_sarkar
Regular Contributor

Manuela,

The sample script that is provided in Feature Class To Geodatabase—Help | ArcGIS Desktop and Table To Geodatabase—Help | ArcGIS Desktop 

along with the CONFIG_KEYWORD can be invoked on demand using Task Scheduler which can be set to execute on a desired date in the month.

Refer Scheduling a Python script to run at prescribed times—Help | ArcGIS Desktop 


I hope this helps!

~Shan


~Shan