I have a script which connects to a database. I'd like to pull out the server,user,password,db from the script and put it into a config file. I'm successfully pulling in the values from the config file. The problem I'm having is the pymssql.connect fails when I have variables in the syntax. I pasted my sample code below. Is this possible?
###database connection  
config = configparser.ConfigParser()  
config.read('test.config')  
server = config['DEFAULT']['SQLServer']  
db = config['DEFAULT']['Database']  
user = config['DEFAULT']['User']  
password = config['DEFAULT']['Password']  
###this works  
####conn = pymssql.connect(host='Server1', user='Joe',password='MyPass', database='MyDB')
###this doesn't
try:
    conn = pymssql.connect(host=server, user=user,password=password, database=db)
except Exception as e:
    print(str(e))
    sys.exit()
 
     
    