I'm a newbie on SQL Server. What is the most preferred way to import shapefile geometry into MS SQL Server 2016. Not sure how to make it right.
Adding to klewis's answer: I got shape2sql.exe to work by adding a Shape2Sql.exe.config file with the following contents:
<?xml version="1.0" encoding="utf-8"?> <configuration> <runtime> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <dependentAssembly> <assemblyIdentity name="Microsoft.SqlServer.Types" publicKeyToken="89845dcd8080cc91" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-18.104.22.168" newVersion="22.214.171.124" /> </dependentAssembly> </assemblyBinding> </runtime> </configuration>
You can change the 126.96.36.199 to whichever version of Microsoft.SqlServer.Types is applicable to your version of SQL Server.
I use a free tool, shape2sql.exe, by SharpGIS.net. Because the tool is unmaintained you may need to copy and rename a dll, SqlServerSpatial110.dll or SqlServerSpatial120.dll to SqlServerSpatial.dll in C:\windows\system32. Also, clear out field "ID Column Name" for the data to import, I'm on Win10 64 bit.
You can use ogr2ogr library to import shapefile to SQL server, check below example and reference:
ogr2ogr -f "MSSQLSpatial" "MSSQL:server=localhost\voledmort;database=myDB;trusted_connection=yes" "countries.shp" -a_srs "EPSG:2249"
You may be interested in "GISquirrel" https://www.gisquirrel.com which includes a tool for importing any vector layer into your SQL Server database, working in ArcMap (It's an extension for ArcGIS Desktop). There's a free trial that works for 20 minutes per session and works with up to 10,000 features in a layer.
here is a step-by-step guide to use the tool http://www.c-sharpcorner.com/UploadFile/898089/how-to-add-world-map-in-sql-server-2012/