- SQL Server Express 2014 running on Windows Home Server 2011
- Python 2.7, SqlAlchemy 1.0.9 running on OSX Yosemite.
As described in the documentation once you have properly specify a DSN (steps above might come handy here...) you can connect to it as follows:
(In the examples i am quering a table on the my Research database with 183600 rowcounts)
import pyodbcimport sqlalchemy as sasa.__version__'1.0.9'
connStr = "mssql+pyodbc://myUsername:myPassword@Research"
engine = sa.create_engine(connStr)
connection = engine.connect()
result = connection.execute('select count(*) as counts from core')
for row in result:
print row['counts']
connection.close()
183600
Here the connection string targets the odbc shared library which in my case sits under /usr/local/lib
connStr = "mssql+pyodbc://myUsername:myPassword@192.168.1.10\SQLEXPRESS/Research?driver=/usr/local/lib/libtdsodbc.so"engine = sa.create_engine(connStr)
connection = engine.connect()result = connection.execute('select count(*) as counts from core')for row in result:print row['counts']connection.close()183600
Note that I havent specified the port. Only the instance name and the database name. Also notice that instance name and database name are separated by a forward slash (ie: SQLEXPRESS/Research) but the host and instance name by a backslash (ie: 192.168.1.10\SQLEXPRESS)
connStr = "mssql+pyodbc://myUsername:myPassword@192.168.1.10:64099/Research?driver=/usr/local/lib/libtdsodbc.so"engine = sa.create_engine(connStr)
connection = engine.connect()result = connection.execute('select count(*) as counts from core')for row in result:print row['counts']connection.close()
183600
Here, after the host i set only the port and then the database name. The instance name does not appear anywhere in the connection string. Also the port is 64099. Quite often this port for other people is 1433. For me however the default port was 64099 as shown by the configuration manager screen attached below. In any case however the port in the connection string should be the same as the port shown in the red box below.