Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """
- In order to use the example you must install pymssql from conda
- conda install -c anaconda pymssql
- """
- import pymssql
- # Using an ini style credentials file for example so will use configparser
- import configparser
- # Setup config parser and read kubernetes secret file
- config = configparser.ConfigParser()
- config.read('/var/run/secrets/user_credentials/mssql_credentials')
- # Setup URI and database to use
- server = 'example-mssql.dev.anaconda.com'
- database = 'SampleDB'
- # Define the connection using variables pulled from secret
- connection = pymssql.connect(
- server,
- config.get('default', 'username'),
- config.get('default', 'password'),
- database
- )
- # Setup the cursor and execute an example query
- cursor = connection.cursor()
- cursor.execute("""
- SELECT TOP (10) [AddressID]
- ,[AddressLine1]
- ,[AddressLine2]
- ,[City]
- ,[StateProvinceID]
- ,[PostalCode]
- ,[SpatialLocation]
- ,[rowguid]
- ,[ModifiedDate]
- FROM [AdventureWorks2016].[Person].[Address]
- """)
- # Print the results from the query
- row = cursor.fetchone()
- while row:
- print(row)
- row = cursor.fetchone()
- # Close the connection once complete
- connection.close()
Add Comment
Please, Sign In to add comment