Best way to export/import MS Sql 2008 Geography data

Pure.Krome picture Pure.Krome · Nov 12, 2008 · Viewed 8.9k times · Source

(ANSWER) How to export some Geography data from a Microsoft Sql Server 2008.

You'll need to use the command line argument BCP to dump the data in it's original (native) format to a binary file. Then on the other server you can bulk insert this binary data back into a table of the same strucutre.

here's some code.

Export

Command Line: bcp "geodata.dbo.GeographyData" out "C:\GeoData.bin" -T -n -S <servername>

Notes

  • This uses a Trusted connection
  • use the bcp /? for more help for your export options if u need to be hardcore.

Importing the data

T-SQL: bulk insert GeographyData from 'C:\GeoData.bin' with (dataFileType='Native')

I learnt all this through the Spatial guru Isaac Kunen and with the help of Kent Tegels, in this discussion thread here.

The reason for the BCP method is highlighted by Isaac in this quote:

Its worth pointing out that WKB is a lossy format, in that it does not store the SRID. So if you extract and insert the WKB, you'll have to carry the SRID yourself. Our internal binary format does store the SRID, so a BCP like this should be less hassle.

HTH.

EDIT: Replaced entire post question as a community wiki .. this this Post being an answer.

Answer

Pure.Krome picture Pure.Krome · Aug 6, 2010

I originally removed the question in the opening post, to replace it with the answer (at the end of '08) ... and make it a wiki.

So yeah .. the OP is the answer :P