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.
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 connect to my database on MS SQL Server 2016 using pyodbc via the below python script from my laptop (on Windows 10) and planning to have the code deployed in a Linux RHEL 6.4 server.
conn=pyodbc.connect('Driver={SQL Server};'
'Server=DB_Instance;'
'Database=DB_Name;'
'UID=user_name;'
'PWD=password;'
'Trusted_Connection=no;');
At my laptop, SQL Server (version: 10.00.17763.01) and SQL Server Native Client 11.0 (version: 2011.110.7493.04) are already available.
While executing the python script from my laptop, I am getting the below error message.
pyodbc.operationalError: ('08001', '[08001] [Microsoft] [ODBC SQL Server Driver][DBNETLIB]SSL Security error (18) (SQLDriverConnect); [08001] [Microsoft] [ODBC SQL Server Driver][DBNETLIB]ConnectionOpen (SECDoClientHandshake()). (772)')
As per the organization standard, TLS 1.0 is disabled on the windows server where the SQL Server is installed in the network. Since I am accessing the database via python script, we cannot temporarily enable TLS 1.0. I am looking for a direction. Any help is greatly appreciated!!
Gord Thompson pointed Guna in the right direction in the comments:
Can you try using ODBC Driver 17 for SQL Server and see if that works for you?
– Gord Thompson
Guna said that this worked:
I was facing different set of errors. While adding the port number in addition to the server name, the problem got resolved. The ODBC Driver name also needs to be updated. conn=pyodbc.connect('Driver={ODBC Driver 17 for SQL Server};' 'Server=DB_Instance,port;' 'Database=DB_Name;' 'UID=user_name;' 'PWD=password;' 'Trusted_Connection=no;');
– Guna
Posting this as a community Wiki just so that any searchers can see quickly that it was answered.
PROBLEM: -
When trying to perform password change for MSSQL server, you get the following error message:-SSL Security error
SOLUTION: -
It's likely an issue with the version of the SQL Native Client driver being used to establish the connection.
Please Download & install "ODBC Driver 13 for SQL Server" on the CPM servers.
https://www.microsoft.com/en-us/download/confirmation.aspx?id=50420
Download 32 bit driver : x86\msodbcsql.msi
Install as usual
Edit MSSQL Platforms to change the connection command from
Driver={SQL Server};Server=%ADDRESS%;Database=%DATABASE%;Uid=%USER%;Pwd=%LOGONPASSWORD%;
to
Driver={ODBC Driver 13 for SQL Server};Server=%ADDRESS%;Database=%DATABASE%;Uid=%USER%;Pwd=%LOGONPASSWORD%;
Restart the CPM service to pick up the platform changes & retest
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')
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