Edit: Sorry I may have placed this in the wrong forum OU. Please move if needed. Thank you
Hey everyone,
I'm creating a simple desktop application that is going to manage hardware and software inventory at my workplace. So far I have gotten the main GUI interface and the Azure SQL database created.
I'm now testing the connection with the below code:
Hey everyone,
I'm creating a simple desktop application that is going to manage hardware and software inventory at my workplace. So far I have gotten the main GUI interface and the Azure SQL database created.
I'm now testing the connection with the below code:
import pyodbc
azureServer = "pythonserver5874.database.windows.net"
azureDB = "inventoryDatabase"
userName = "lol"
password = "lol"
driver = "{ODBC Driver 17 for SQL Server}"
with pyodbc.connect(
"DRIVER=" + driver + ";SERVER=" + azureServer + ";PORT=1433;DATABASE=" + azureDB + ";UID=" + userName +
";PWD=" + password) as dbConnection:
with dbConnection.cursor() as sqlCMD:
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()The code works but my question is what exactly is the purpose of the strings in the connection setup on lines 10 & 11? Obviously they are needed since if I take them out I receive the below error. The reason I'm confused is if I take out just the port number "1433" the connection and code still works? Error:Traceback (most recent call last):
File "tc.py", line 9, in <module>
with pyodbc.connect(driver + azureServer + azureDB + userName + password) as dbConnection:
pyodbc.InterfaceError: ('IM002', '[IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified (0) (SQLDriverConnect); [IM002] [Microsoft][ODBC Driver Manager] Invalid connection string attribu
te (0)')Not exactly sure if I understand this error.
