title: OGR2OGR with MS SQL on Ubuntu 16.04
body: <p>I need to access a Microsoft SQL Server with OGR2OGR from an Ubuntu Server 16.04. It is working on Microsoft, so the basic setup is fine.</p>
  
  <p>My problem is that when I run my OGR2OGR command (after installing GDAL with sudo apt-get install gdal-bin):</p>
  
  <pre><code>ogr2ogr -overwrite -f MSSQLSpatial "MSSQL:server=tcp:&lt;DATABASE_SERVER&gt;,&lt;PORT&gt;;database=&lt;DATABASE_NAME&gt;;uid=&lt;USER&gt;;Pwd=&lt;PASSWORD&gt;;" "&lt;IMPORT PATH FILE&gt;" -nln "&lt;TABLE NAME&gt;" -progress
  </code></pre>
  
  <p>I get the error:</p>
  
  <blockquote>
    <p>ERROR 1: Unable to initialize connection to the server for MSSQL:"DATABASE_SERVER";
    [unixODBC][Driver Manager]Can't open lib 'SQL Server' : file not found
    Try specifying the driver in the connection string from the list of available drivers:</p>
  </blockquote>
  
  <p>I tried to install Microsoft ODBC Driver for SQL Server based on <a href="https://msdn.microsoft.com/en-us/library/hh568454(v=sql.110).aspx" rel="nofollow noreferrer">this</a> instruction, but it cannot be installed when gdal is installed. The error is:</p>
  
  <blockquote>
    <p>Some packages could not be installed. This may mean that you have
    requested an impossible situation or if you are using the unstable
    distribution that some required packages have not yet been created
    or been moved out of Incoming.
    The following information may help to resolve the situation:</p>
    
    <p>The following packages have unmet dependencies:
     msodbcsql : Depends: unixodbc-utf16 (>= 2.3.1-1) but it is not going to be installed
    E: Unable to correct problems, you have held broken packages.</p>
  </blockquote>
  
  <p>I managed to install the Microsoft ODBC driver after a while but it meant removing GDAL. So I can either have GDAL or the Microsoft ODBC driver. Is there a way to solve this problem?</p>
  
  <p>Thanks for your help!</p>
  
  <p><strong>UPDATE (2017.01.03):</strong> I found the following solution and I also commented on the according article on the MSDN Blog (so far without reply) <a href="https://blogs.msdn.microsoft.com/sqlnativeclient/2016/10/20/odbc-driver-13-0-for-linux-released/comment-page-1/#comment-6905" rel="nofollow noreferrer">here</a></p>
  
  <p>Install UnixODBC if not already there</p>
  
  <pre><code>sudo apt-get install unixodbc unixodbc-dev
  </code></pre>
  
  <p>Download from somewhere: msodbcsql-11.0.2270.0.tar.gz  (it could be better to use msodbcsql-13.x.x.x.tar.gz but I was not able to find it) and</p>
  
  <pre><code>tar xvfz msodbcsql-11.0.2270.0.tar.gz
  cd msodbcsql-11.0.2270.0
  ldd lib64/libmsodbcsql-11.0.so.2270.0
  </code></pre>
  
  <p>If there are missing dependencies install them, in my case it could be done like this: (everything except the apt-get install is to fix the naming of the file by creating a link:)</p>
  
  <pre><code>sudo apt-get install libssl1.0.0 libssl-dev
  cd /lib/x86_64-linux-gnu
  sudo ln -s libssl.so.1.0.0 libssl.so.10
  sudo ln -s libcrypto.so.1.0.0 libcrypto.so.10
  </code></pre>
  
  <p>Installing and cleaning up:</p>
  
  <pre><code>sudo bash ./install.sh install --force --accept-license
  
  rm -rf /tmp/msodbcubuntu
  </code></pre>
  
  <p>If the Driver is not found by the tool using it, (e.g. ogr2ogr or pyodbc) edit /etc/odbcinst.ini and create a connector for [SQL Server]</p>
  
  <pre><code>[SQL Server]
  Description=Microsoft ODBC Driver 11 for SQL Server
  Driver=/opt/microsoft/msodbcsql/lib64/libmsodbcsql-11.0.so.2270.0
  Threading=1
  UsageCount=2
  </code></pre>