Connecting to MS SQL#

Anaconda Enterprise enables you to easily connect to an Microsoft SQL server database, to access the data stored in it.

Before you can do so, however, you’ll need to install the pymssql conda package which contains a simple database interface for Python to work with MS SQL Server:

conda install -c anaconda pymssql

NOTE: Any packages you install from the command line are available during the current session only. If you want them to persist, add them to the project’s anaconda-project.yml file. For more information, see Developing a project.


If you require a trusted connection, see the instructions for connecting to MS SQL using Kerberos authentication.

You can then use code such as this to connect to the MS SQL database from within a notebook session:

import pymssql
import configparser

Setup config parser and read Kubernetes secret .ini style credentials file. For example:

config = configparser.ConfigParser()'/var/run/secrets/user_credentials/mssql_credentials')

# Setup URI and database to use
server = ''
database = 'SampleDB'

# Define the connection using variables pulled from secret
connection = pymssql.connect(
    config.get('default', 'username'),
    config.get('default', 'password'),

# Setup the cursor and execute an example query
cursor = connection.cursor()
SELECT TOP (10) [AddressID]
FROM [AdventureWorks2016].[Person].[Address]

# Print the results from the query
row = cursor.fetchone()
while row:
    row = cursor.fetchone()

# Close the connection once complete

See Storing secrets for information about adding credentials to the platform, to make them available in your projects. Any secrets you add will be available across all sessions and deployments associated with your user account.