SQL Server and Python (from a RaspBerry PI)


The version of the OS of the Raspberry for this particular case is Raspbian Jessi, but it appears to work with the NOOBS version. Also, this tutorial is taken from tutorials of another UNIX based OS, like Mac and another versions of Linux. So, if you can search for the equivalents of the modules or services on your OS version, then, I think it may work well.

First we need to set something, I really (at this point) don’t understand the real interaction between all the modules, but I can make some graphic explanations on how the connections are working, and what type of data it must contain.

Python <—–> pyodbc<—->Driver<—->MS SQL

The Driver is actually made of two parts, UnixODBC and the TDS driver, but for show we encapsulate it in a single package.

The unixODBC is like a service in what we make references. Is a file that we edit in order to make the reference in whatever Plugin or language we are using, usually the plugins make reference to this file. If you don’t make a good reference, they are going to be throwing errors like ‘Driver not found’.

TDS is the driver witch we make reference to in the unixODBC file. This driver allow us to communicate to the MS SQL databases. This is the software that makes the connection, so, if you don’t have this is not going to work. If you don’t configure this software, it’s going to make a mess too, and is going to say something about ‘Can’t get access’ or ‘Can’t get connection’, this two problems are way too common if is not installed the driver or configured correctly.

Installation and configuration

As a summary of the previous section. We need at least 3 things, a module that can talk to MSSQL (Microsoft SQL), a local module in with witch we are making references unixODBC, and the plugin of our language that is calling the local module that make the link to MS. In this case we are using Python and pyodcb.

Installing pyodbc

There are two ways of doing this, we can either use pip to install it, or we can go directly to apt-get install or whatever command your version of linux uses to install repositories.

sudo apt-get install python-pyodbc


pip install pyodbc

once installed we can check if is installed by writing our first part of the program.

import pyodbc

We save the file, and on the terminal we run python Conection.py

It should not give us any error, if some error appears…well google it or ask for help in here.





Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s