I am trying to connect to SQL Server using PYODBC inside AWS Lambda. I set up an EC2 instance and installed all dependencies and packages needed. I am able to query SQL within EC2 but not within Lambda.
Seems like I am missing a config or a library to set up the connections when packaging. I have copied the SQL driver in /opt/microsoft/msodbcsql17/lib64/libmsodbcsql-17.3.so.1.1 location. Copied the odbc.ini and odbcinst.ini files as needed. Copied the libtds and libodc* as well.
The error that I get when I package all the libraries and dependencies into lambda package is below:
[IM002] [unixODBC][Driver Manager]Data source name not found, and no default driver specified (0) (SQLDriverConnect)
My odbc.ini and odbcinst.ini is below:
odbc.ini
[DEV]
Driver = ODBC Driver 17 for SQL Server
Description = DEV
Trace = No
Server = abc.net,1234
odbcinst.ini
[ODBC Driver 17 for SQL Server]
Description=Microsoft ODBC Driver 17 for SQL Server
Driver=/opt/microsoft/msodbcsql17/lib64/libmsodbcsql-17.3.so.1.1
UsageCount=1
I tried providing the DSN and also explicitly mentioning the Driver and Server name in pyodbc.connect. Still no luck!
Any help or direction would be appreciated!
TIA
odbc.ini
andodbcinst.ini
files? Do you have the driver specified correctly? Also, if you have a connection string, could you provide that? Perhaps there is an issue with that instead. – gmileyDriver=
should be at the beginning of a line. – Gord Thompsonodbcinst -j
will show you where it is looking. If you mean to create a separate file to define your DSN then you can do that and then use something likepyodbc.connect('FILEDSN=/path/to/my.dsn')
. – Gord Thompson