'Login failed for the user '' SQL Server when connecting using python from EMR server

I'm trying to connect to SQL Server Database from AWS EMR server.

$cat /etc/odbcinst.ini
[ODBC Driver 17 for SQL Server]
Description=Microsoft ODBC Driver 17 for SQL Server
Driver=/opt/microsoft/msodbcsql17/lib64/libmsodbcsql-17.8.so.1.1
UsageCount=1

and I modified the .odbc.ini file in my home directory like this.

$cat .odbc.ini
[ODBC Data Sources]
studylog = ODBC17Driver

[studylog]
Driver          = /opt/microsoft/msodbcsql17/lib64/libmsodbcsql-17.8.so.1.1
Description     = My Description
Server          = hostname.amazonaws.com

output of odbcinst -j command

unixODBC 2.3.7
DRIVERS............: /etc/odbcinst.ini
SYSTEM DATA SOURCES: /etc/odbc.ini
FILE DATA SOURCES..: /etc/ODBCDataSources
USER DATA SOURCES..: /mnt/efs/home/username/.odbc.ini
SQLULEN Size.......: 8
SQLLEN Size........: 8
SQLSETPOSIROW Size.: 8

output of odbcinst -q -d command

[ODBC Driver 17 for SQL Server]

output of odbcinst -q -s command

[studylog]

Python script I'm using to connect to SQL Server

import pyodbc

host = "hostname.amazonaws.com"
user="DBUser"
password="Password"
db="dbname"

details = {
 'server' : host,
 'database' : db,
 'username' : user,
 'password' : password
 }

# ODBC Driver 17 for SQL Server
connect_string = 'DRIVER={{ODBC Driver 17 for SQL Server}};SERVER={server};PORT={{1433}}; DATABASE={database};UID={username};PWD={password}'.format(**details)
connection = pyodbc.connect(connect_string)
print(connection)

output of my python script

pyodbc.InterfaceError: ('28000', "[28000] [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Login failed for user 'DBUser'. (18456) (SQLDriverConnect)")

What's going wrong in this? Thank you in advance.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source