How to connect to a remote Microsoft SQL server

Posted March 1, 2018 11k views
PythonUbuntu 16.04

I searched the current questions and didn’t find anything about connecting to a remote microsoft sql server. There are plenty of questions about mysql remote connection, but nothing for microsoft sql server.

The microsoft sql server is not installed on Digital Ocean. It is a remote server installed somewhere else.

I did some google searches and this was about the best I came up with,

I also ran across this alternative,

Does anyone have any experience with any of this? Thank you in advance for any advice.

I will try the instructions in the first link above and see how it goes.

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
3 answers

How did it go?

Seems like the first link is correct, you’ll need the pyodbc (or PyMSSQL) driver to connect to MS SQL servers.

Simple example from:

import pyodbc 
server = '' 
database = 'mydb' 
username = 'myusername' 
password = 'mypassword' 
cnxn = pyodbc.connect('DRIVER={ODBC Driver 13 for SQL Server};SERVER='+server+';DATABASE='+database+';UID='+username+';PWD='+ password)
cursor = cnxn.cursor()

Let me know how you made out, would be happy to help you further.

Thanks for the reply. For now, my client has put the MS SQL part on hold and will go with MySQL since I already have that working. At least I always have this as a reference on how to do it. :)

Awesome, great to hear!