-1

I have used the following code:

    cnxn = pyodbc.connect(
    server="SERVER NAME",
    database="DATABASE NAME",
    user=sql_username,
    password=sql_password,
    port=1433,
    driver='{ODBC Driver 17 for SQL Server}'
    )

And the error i get is:

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

Goal: have an aws lambda function which will run sql queries in my MSSQL database.

Set up: i have all the relevant pyodbc dependencies / drivers for my lambda which i got from here: https://github.com/kuharan/Lambda-Layers

Points to note:

  • I want to use SQL server authentication (Not windows authentication).
  • I have seen posts about where people used "Trused_Connection=yes" which is what results in windows authentication being used. I have not used that here.
  • I have tried with "Trused_Connection=no" and get the same error
  • I have tried driver='{SQL Server}' but this does not work as the driver can't be found and i can't find where to download this driver to add to my lambda zip file
  • The Username and Password are correct.
  • I have used the RDS endpoint as the server name
polo
  • 155
  • 4
  • 11
  • 1
    `The Username and Password are correct.` <- that's not what the error message seems to indicate. Let me ask this: does the password contain any special characters like `$` or `?`? They probably need to be escaped for whatever the heck "aws lambda" uses to send the password across... – Aaron Bertrand Apr 02 '22 at 19:11
  • Does [this](https://stackoverflow.com/questions/17372606/sqlserver-login-failed-for-user) solve your problem? – Zakk Apr 02 '22 at 19:13
  • Look in the SQL Server error log. It will contain the exact reason for the failure. – John Gordon Apr 02 '22 at 19:13
  • `sqladmin` is not a standard account name on SQL Server. Is it one that you created? Can you use that account name and password to login from standard tools like SSMS? – AlwaysLearning Apr 02 '22 at 23:14
  • @AaronBertrand please could you submit your comment as an answer? Escaping the special characters did the trick for this error! Still having connection issues but that's a whole new error – polo Apr 04 '22 at 12:26

1 Answers1

-1

The Username and Password are correct.

That may be true, but keep in mind that how a password gets passed through may require escaping. Characters like $ can be problematic, as I mention here (this isn’t AWS but similar concept).

Aaron Bertrand
  • 272,866
  • 37
  • 466
  • 490