Home > OS >  pyodbc encrypt username and password
pyodbc encrypt username and password

Time:11-10

I am using VSCode, pyodbc-4.0.34, Python 3.10.7.

Code from enter image description here

Correspondingly, you can modify your code:

import pyodbc
import pandas as pd
import sys
server = sys.argv[1]
database = sys.argv[2]
username = sys.argv[3]
password = sys.argv[4] 
cnxn = pyodbc.connect('DRIVER={SQL Server};SERVER=' server ';DATABASE=' database ';UID=' username ';PWD='  password)
cursor = cnxn.cursor()
# select 26 rows from SQL table to insert in dataframe.
query = "SELECT [CountryRegionCode], [Name] FROM Person.CountryRegion;"
df = pd.read_sql(query, cnxn)
print(df.head(26))

Then manually enter the parameters when running the python file.

  • Related