I am getting quite confused on how to approach connecting to SQL server from a Python Lambda function. At this point, I am just trying to connect to my SQL Server (Azure) instance from the recommended AMI image .
The first and most popular approach seems to be using pymssql. Within that, it seems like you can go with the precompiled FreeTDS version (export PYMSSQL_BUILD_WITH_BUNDLED_FREETDS=1
) or you can install FreeTDS on your system.
I have tried both and always ended up with the following error:
>>> pymssql.connect('myserver.database.windows.net', 'myuser@myserver.database.windows.net', 'mypass', 'mydb')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "pymssql.pyx", line 641, in pymssql.connect (pymssql.c:10824)
pymssql.OperationalError: (20002, 'DB-Lib error message 20002, severity 9:\nAdaptive Server connection failed (myserver.database.windows.net:1433)\n')
Note, that if I install FreeTDS on the system and attempt to connect with tsql
, I have no problems at all.
I can provide more info on exactly how my installs are setup if someone can help me with this approach. Alternatively, I am happy to go the pyodbc route but would need some help in that direction, too.
Update:
I tried going the pyodbc route and managed to get the drivers installed following this guide. Will update on future progress