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
After digging through multiple blogs and links, the answer is as simple as explicitly mentioning the location of driver when you connect using pyodbc.
conn = pyodbc.connect('Driver=msodbcsql17/lib64/libmsodbcsql-17.3.so.1.1;Server=server,port;UID=uname;PWD=pwd;database=db_name;Encrypt=YES;TrustServerCertificate=Yes')
Related
I am not able to connect to tally odbc from another network. I have whitelisted my IP and Opened port 9000. Tally is installed on a machine in cloud. Here is what I am doing:
import pyodbc
conn = pyodbc.connect('Dsn=TallyODBC64_9000;Driver={Tally ODBC Driver};server=20.xx.xx.xx;port=9000')
It is giving me this error:
InterfaceError: ('IM002', '[IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified (0) (SQLDriverConnect)')
I have looked on the internet but couldn't find anything on connecting outside of your network.
Questions:
Do I need to install Tally ODBC Driver on my machine?
Can you guide me on where I am going wrong.
Thanks.
Try Accessing your server in browser http://20.xx.xx.xx:9000
if it shows <RESPONSE>TallyPrime Server is Running</RESPONSE>
then try connecting using ODBC
if its shows nothing, then you need to check whether Port configured in Tally is allowed in Cloud security setting and system firewall settings
I am getting a strange error with Python condo environments and PyODBC. I have multiple Conda environments, I am able to connect from one of the environment (from a Linux machine) to SQL Server hosted on Azure but not from the other one. Both Python environments have version 3.7.7 of Python and version 4.0.0 of Pyodbc. Code is exactly the same and connection string uses SQL Server 17 driver.
conn_str='DRIVER={ODBC Driver 17 for SQL Server};SERVER=' +server+';Authentication=ActiveDirectoryPassword;DATABASE='+database+';UID='+self.user_name+';PWD='+self.password
Error is :
pyodbc.OperationalError: ('HYT00', '[HYT00] [Microsoft][ODBC Driver 17 for SQL Server]Login timeout expired (0) (SQLDriverConnect)')
As you can see above, the issue might be DNS-related. In the
connection string, try using an IP address instead of the hostname,
or check your DNS setup.
Try downgrade to ODBC driver 13 and have a try. For that version 17
needs to be uninstalled.
Try using connect from SQL Authentication instead of Active Directory
Password.
The SQL Server ODBC drivers for Linux from Microsoft are unable to determine instance names.
I am trying to get a python script to deploy to Cloud Foundry which uses pyobdc to connect to sql server and execute commands. My pyobdc connection statement looks like so:
warehouse_connection = pyodbc.connect(f'Driver={DRIVER}'
f';Server={SERVER}'
f';Database={DATABASE}'
f';UID={USERNAME}'
f';PWD={PASSWORD}'
';Trusted_Connection=no')
warehouse_cursor = warehouse_connection.cursor()
The driver I am using is ODBC Driver 17 for SQL Server and I have the odbcinst.ini file which looks like so:
[ODBC Driver 17 for SQL Server]
Description=Microsoft ODBC Driver 17 for SQL Server
Driver=/home/vcap/deps/0/apt/opt/microsoft/msodbcsql17/lib64/libmsodbcsql-17.6.so.1.1
UsageCount=1
My script works fine on my local machine so I know the access account info is up to date and I have other scripts that use that driver which work fine, but when I try to deploy to Cloud Foundry I get the following error:
pyodbc.OperationalError: ('HYT00', '[HYT00] [Microsoft][ODBC Driver 17 for SQL Server]Login timeout
expired (0) (SQLDriverConnect)')
I tried changing the trusted connection variable, made sure my apt/environment was up to date, I am not sure what I am missing. Is there in issue with pyodbc in Cloud Foundry or am I getting something wrong?
Thanks.
In case anyone comes back an looks at this, it turns out all we needed to do was open up firewall access from that cloud foundry space and then it worked. Posted this a while ago and realized I should probably answer it.
I am having issues connecting to an Azure database from a Virtual Machine running Ubuntu 16.04. This VM is in Google cloud. I get the following error
pypyodbc.Error: (u'IM002', u'[IM002] [unixODBC][Driver Manager]Data source
name
not found, and no default driver specified')
This code works fine locally on my PC in a Jupyter notebook. I have added the Google Cloud VM's IP address to the let it through the Azure firewall- so that doesn't appear to be the cause of the error. I have observed that I can replicate the original error message in Jupyter notebook if I change the driver "SQL Server Native Client" from 11.0 to 13.0
This all points to driver issues. A similar issue has been discussed here
With the problem being linked to "not defining that driver in the "/etc/odbcinst.ini" file."
My odbcinst.ini file contains the following information:
[ODBC Driver 13 for SQL Server]
Description=Microsoft ODBC Driver 13 for SQL Server
Driver=/opt/microsoft/msodbcsql/lib64/libmsodbcsql-13.1.so.8.0
UsageCount=1
My odbc.ini file contains no information.
If I change my connection string in my code to "Driver={SQL Server Native Client 13.0" I get the same error. My other thought was to run with a version 11 of the driver. However there doesn't appear to be one for Ubuntu (only SUSE & RedHat Linux).I am new to this subject area- so feeling stuck. Any suggestions on a next logical step to resolve the connection issue.
Regards
Mike
Am having an issue connecting to a Microsoft SQL Server instance from pyODBC within an Ubuntu (12.10) machine.
The error I am getting back is:
pyodbc.Error: ('IM002', '[IM002] [unixODBC][Driver Manager]Data Source name not found, and no default driver specified (0) (SQLDriverConnect)')
The connection string am using for pyodbc is:
self.corpus_cnxn = pyodbc.connect('DRIVER={FreeTDS};SERVER=UKEDN-06880;DATABASE=db1;UID=user;PWD=pass')
This seems to work fine from pyODBC within Windows (just need to change the DRIVER to 'SQL Server' instead of 'FreeTDS'), and it work fine when I try to connect from the Ubuntu machine using the tsql Tool from the terminal, with the following command:
tsql -S UKEDN-06880 -p 1433 -U user -P pass
I can select any table with no issues, it just doesn't seem to work from within pyODBC.
Any help or advice will be much appreciated, my Linux skills are uber weak and am totally stuck, although since it works from tsql I get the feeling that am very close!
It looks like you have gotten freeTDS to work correctly since you can use tsql. Have you tried to connect with isql?
Look at this howto for a detailed walk through. The part I think you need is in setting up unixodbc a little ways down the page.
first stape
$ sudo apt-get install libmdbodbc1
edit the file /etc/odbcinst.ini like this
[Microsoft Access Driver (*.mdb)]
Description = Microsoft Access Driver (*.mdb)
Driver = /path/to/file/libmdbodbc.so
Setup = /path/to/file/libtdsS.so
CPTimeout =
CPReuse =
And the file /etc/odbc.ini
[Microsoft Access Driver (*.mdb)]
Description = SQL Server
Driver = Microsoft Access Driver (*.mdb)
Trace = No
TraceFile = /tmp/mssodbc.log