Feb-23-2021, 11:51 PM
I rewrote it. It's just easier for me read like this being new. I'm just going to assume Azure needs the connection string in that format for it to work.
import pyodbc def databaseConnection(driver, server, database, user, pwd): connectionString = f"DRIVER={driver};SERVER={server};PORT=1433;DATABASE={database};UID={user};PWD={pwd}" conn = pyodbc.connect(connectionString) sqlCMD = conn.cursor() sqlCMD.execute("SELECT TOP 3 name, collation_name FROM sys.databases") row = sqlCMD.fetchone() while row: print(str(row[0]) + " " + str(row[1])) row = sqlCMD.fetchone() def main(): azureServer = "pythonserver5874.database.windows.net" azureDB = "inventoryDatabase" userName = "lol" password = "lol" driver = "{ODBC Driver 17 for SQL Server}" databaseConnection(driver, azureServer, azureDB, userName, password) if __name__ == '__main__': main()