How to connect to a remote Microsoft SQL server

March 1, 2018 236 views
Python Ubuntu 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.

3 Answers
dc250org March 16, 2018
Accepted Answer

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 = 'tcp:myserver.database.windows.net' 
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. :)

Have another answer? Share your knowledge.