[gdal-dev] Import Shapefile into SQL Server on Ubuntu

Peter Marlow Peter.Marlow at scisys.co.uk
Fri Nov 30 02:12:30 PST 2018


I've had a bit of time to look at this again and I have got it working, I didn't rebuild GDAL myself though, just used a build that had ODBC support. I've listed the steps below in case anyone else finds them useful, they are as Mateusz suggested so thank you for your help!

Steps to connect to MS SQL Server using GDAL/ogr2ogr on Ubuntu 16.04:

--- Install GDAL (version with ODBC support)
sudo apt-get update
sudo apt-get install gdal-bin


--- Install unixodbc
sudo apt-get install unixodbc unixodbc-dev


--- Install Microsoft ODBC Driver 17 for SQL Server on Ubuntu 16.04 (see https://docs.microsoft.com/en-us/sql/connect/odbc/linux-mac/installing-the-microsoft-odbc-driver-for-sql-server?view=sql-server-2017)
sudo su
curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list > /etc/apt/sources.list.d/mssql-release.list
exit
sudo apt-get update
sudo ACCEPT_EULA=Y apt-get install msodbcsql17


--- Run ogr2ogr using driver
ogr2ogr -f MSSQLSpatial "MSSQL:server=[server];database=[database];uid=[username];Pwd=[password];Driver={ODBC Driver 17 for SQL Server}" [shape file]


Thanks,
Pete

-----Original Message-----
From: gdal-dev <gdal-dev-bounces at lists.osgeo.org> On Behalf Of Mateusz Loskot
Sent: 22 October 2018 16:31
To: gdal-dev at lists.osgeo.org
Subject: Re: [gdal-dev] Import Shapefile into SQL Server on Ubuntu

On Mon, 22 Oct 2018 at 17:25, Peter Marlow <Peter.Marlow at scisys.co.uk> wrote:
>
> I’m trying to import a Shapefile into an SQL Server database using ogr2ogr on Ubuntu. The command I’m running looks like:
>
> ogr2ogr -f MSSQLSpatial 
> "MSSQL:server=localhost;database=[database-name];username=sa;password=
> *****;trusted_connection=yes" [path-to-shape-file]
>
> It returns an error stating:
>
> ERROR 1: Unable to find driver `MSSQLSpatial'.

I guess, GDAL/OGR version you are using on Linux is not built with ODBC/SQL Server support.

> Is it possible to get the driver on linux? Or use an alternative driver? I’ve had a google and can’t seem to see any workarounds.
>
> The docs here (https://www.gdal.org/drv_mssqlspatial.html) talk about 
> specifying a Driver parameter that could be a custom SQL Server driver, however this is in the connection string and not as a parameter for the ogr2ogr command.

Once you get GDAL/OGR built with SQL Server, install ODBC Driver for SQL Server (there are clear docs on Microsoft site, you will find easily searching the web)

Then, try sticking the Driver option into the connection string Driver={ODBC Driver 11 for SQL Server} Driver={ODBC Driver 13 for SQL Server} Driver={ODBC Driver 13.1 for SQL Server} Driver={ODBC Driver 17 for SQL Server} depending which version you install.

Best regards,
--
Mateusz Loskot, http://mateusz.loskot.net _______________________________________________
gdal-dev mailing list
gdal-dev at lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/gdal-dev


SCISYS UK Limited. Registered in England and Wales No. 4373530.
Registered Office: Methuen Park, Chippenham, Wiltshire SN14 0GB, UK.
 
Before printing, please think about the environment.



More information about the gdal-dev mailing list