I'm attempting to connect to a database within a local Docker image I've spun up using DBI and am running into some pretty cryptic errors... I've successfully started the Docker container (below shows result of docker ps -a):
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
131ab042012c mcr.microsoft.com/mssql/server:2017-latest "/opt/mssql/bin/nonr…" 27 minutes ago Up 27 minutes 127.0.0.1:1433->1433/tcp admiring_northcutt
I then try to connect via:
pool<- pool::dbPool(odbc::odbc(),
Driver = "ODBC Driver 17 for SQL Server",
Server = "localhost",
Database = "master",
UID = "sa",
PWD = "***********",
Port = 1433)
and receive the error:
Error: nanodbc/nanodbc.cpp:1021: 00000: [Microsoft][ODBC Driver 17 for SQL Server]Client unable to establish connection [Microsoft][ODBC Driver 17 for SQL Server]Invalid connection string attribute
Checking my odbc driver using odbc::odbcListDrivers() returns the output below, so the drivers seem to be present.
name attribute value
1 ODBC Driver 17 for SQL Server Description Microsoft ODBC Driver 17 for SQL Server
2 ODBC Driver 17 for SQL Server Driver /usr/local/lib/libmsodbcsql.17.dylib
3 ODBC Driver 17 for SQL Server UsageCount 2
In addition, executing the container and attempting to connect to the database via the commands:
docker exec -it <container-name> /bin/bash
/opt/mssql-tools/bin/sqlcmd -S 127.0.0.1 -U sa -P '<password>'
EDIT: The above method now works and I'm able to actively query within the database. I know that the error can't be due to invalid login credentials because I'm using the same exact ones as I ran above in the container.
This same process works for a coworker, so I'm wondering if it's a local issue with my set up. We already compared our .ini files as suggested in this link and they're identical, I've clean re-installed Docker, and I've even ran the coworker's identical container with no luck. Any ideas what could be happening here?
Computer specs:
MacBook Pro (16-inch 2019)
OS: macOS Monterey (version 12.2.1)
Processor: 2.3 GHz 8-Core Intel Core i9
Memory: 16GB 2667MHz DDR4
Startup Disk: Macintosh HD
Graphics: AMD Radeon Pro 5500M 4 GB
Rstudio Version: 2021.09.0 Build 351
OpenSSL Version: 1.1
Related
I have a docker container that contains a database which I'm able to access with the user id and password below and am running into an error when attempting to connect using this code:
con <- DBI::dbConnect(odbc::odbc(),
Driver = "ODBC Driver 17 for SQL Server",
Port = 1433,
Server = "localhost",
Database = "master",
UID = "sa",
PWD = "password!23")
The error is:
Error: nanodbc/nanodbc.cpp:1021: 00000: [Microsoft][ODBC Driver 17 for SQL Server]Client unable to establish connection [Microsoft][ODBC Driver 17 for SQL Server]Invalid connection string attribute
Any ideas on what the issue could be?
Computer specs:
MacBook Pro (16-inch 2019)
OS: macOS Monterey (version 12.2.1)
Processor: 2.3 GHz 8-Core Intel Core i9
Memory: 16GB 2667MHz DDR4
Startup Disk: Macintosh HD
Graphics: AMD Radeon Pro 5500M 4 GB
Rstudio Version: 2021.09.0 Build 351
OpenSSL Version: 1.1
EDIT:
Switching the code such that the server references 127.0.0.1, 1433 fixed the latter error, but now I'm receiving the former:
Error: nanodbc/nanodbc.cpp:1021: 00000: [Microsoft][ODBC Driver 17 for SQL Server]Client unable to establish connection
Code used to attempt to create connection:
con <- DBI::dbConnect(odbc::odbc(),
driver = "ODBC Driver 17 for SQL Server",
server = "127.0.0.1,1433",
database = "master",
uid = "sa",
pwd = "password!23")
Docker command used to run the container:
docker run -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=password!23' -p '1433:1433' --name sql3 -d mcr.microsoft.com/mssql/server:2017-latest
Container attributes (docker ps --no-trunc):
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f755291fe369f9ad3339626528999bb7cef3d7947e68045b60fc4591f865aace mcr.microsoft.com/mssql/server:2017-latest "/opt/mssql/bin/nonroot_msg.sh /opt/mssql/bin/sqlservr" 24 minutes ago Up 41 seconds 0.0.0.0:1433->1433/tcp sql3
I don't have incontrovertible proof that it was Monterey 12.2.1 that was giving me problems, but downgrading to Big Sur 11.6.4 did resolve my issue (and gave me an opportunity to install dependencies in a more conscientious way).
Thanks everyone for your guidance!
I am using pyodbc to connect to an azure synapse db from a centos box.
I get
"Unable to set SQL_ATTR_CONNECTION_POOLING attribute"
right from the pyodbc.connect() method.
I did try to set pyodbc.pooling = False, before trying to get the connection, but then I get
"'utf-8' codec can't decode byte 0xf5 in position 2: invalid start byte"
which is weird since I am not executing any query, just pyodbc.connect(...)
I also tried to set odbc trace but I get nothing in the log...
Here's my env:
OS: CentOS Linux release 7.5.1804 (Core)
Python: Python 3.7.4
Pyodbc: Version: 4.0.30
ODBC: unixODBC 2.3.7
odbcinst.ini:
[ODBC Driver 17 for SQL Server]
Description=Microsoft ODBC Driver 17 for SQL Server
Driver=/opt/microsoft/msodbcsql17/lib64/libmsodbcsql-17.6.so.1.1
UsageCount=1
Is there a way to troubleshoot ?
Forgot to mention that I get the same message if I use the wrong driver name, or any of the other connection params.
thank you in advance
We are glad to hear that the error is solved.
For details, please see the GitHub here:
https://github.com/mkleehammer/pyodbc/issues/847#issuecomment-733087938
Getting the "[unixODBC][Driver Manager]Data source name not found, and no default driver specified" despite /etc/odbc.ini having the DSN referenced in the connection string. Why would this be happening and what can be done?
Trying to set up pyodbc for connecting to MSSQLServer using the docs (centos 7). Yet, when trying to actually connect to the database,
import pyodbc
# setup db connection
server = 'myserver'
database = 'mydb'
username = 'myusername'
password = 'mypassword'
cnxn_str = 'DSN=MyMSSQLServer;DATABASE='+database+'UID='+username+'PWD='+password+'MultipleActiveResultSets=True;'
cnxn = pyodbc.connect(cnxn_str)
getting error "[unixODBC][Driver Manager]Data source name not found, and no default driver specified", even though when running:
[mapr#mnode01 ~]$ cat /etc/odbc.ini
[MyMSSQLServer] Driver=ODBC Driver 13 for SQL Server
Description=My MS SQL Server
Trace=No
Server=<now using my sql server ip>
I can see that the DSN that I referenced in the python code is recorded in the /etc/odbc.ini file. Does anyone know what could be going on here? Thanks.
Note: I initially ran the pyodbc setup exactly as specified in the docs, but later re-did this step to use the ip address of the sql server I wanted to connect to:
vi /home/user/odbcadd.txt
[MyMSSQLServer] Driver = ODBC Driver 13 for SQL Server
Description = My MS SQL Server
Trace = No
Server = <my sql server ip>
and just re-ran the write to odbc.ini:
sudo odbcinst -i -s -f /home/user/odbcadd.txt -l
The solution commented by user Gord Thompson solved my problem. The ~/odbcadd.txt file that I was using to fill the /etc/odbc.ini file needed to have the 'Driver=' line on a separate line from the DSN to look like:
[mapr#mnode01 ~]$ cat /etc/odbc.ini
[MyMSSQLServer]
Driver=ODBC Driver 13 for SQL Server
Description=My MS SQL Server
Trace=No
Server=172.18.4.38
I've been trying to establish a connection to an MS Access database I have on my local hard drive using FreeTDS and UnixODBC. My ultimate goal is to open the connection in R via RODBC and implement some SQL scripts developed for this specific database to extract data. I've followed advice from this page (How do I install RODBC on Mac OS X Yosemite with unixodbc and freetds?), but am still having trouble.
When I implement isql in terminal I get the following error message.
[S1000][unixODBC][FreeTDS][SQL Server]Unable to connect to data source
[01000][unixODBC][FreeTDS][SQL Server]Unknown host machine name.
[ISQL]ERROR: Could not SQLConnect
I'm assuming my error is in how I've identified the host in my various setup files, which are as follows.
freetds.conf
[global]
; tds version = 8.0
; dump file = /tmp/freetds.log
; debug flags = 0xffff
; timeout = 10
; connect timeout = 10
text size = 64512
[my_db]
# insert the actual host below
host = My_computer_name.local
port = 1433
tds version = 8.0
odbc.ini
[my_db]
Driver = MSSQL
Servername = My_computer_name.local
Port = 1433
Database = /filepath_to_db/my_db.mdb
TDS_Version = 8.0
odicinst.ini
[MSSQL]
Description = Microsoft SQL Server driver
Driver = /usr/local/Cellar/freetds/1.00.39/lib/libtdsodbc.so
Setup = /usr/local/Cellar/freetds/1.00.39/lib/libtdsodbc.so
FreeTDS is for connecting to Microsoft SQL Server and Sybase databases. It is not designed to work with Microsoft Access databases.
I was trying to setup ODBC connection for Hive. I followed the below steps but it didn't worked.
User DSN-->Add--> Hortonworks Hive ODBC Driver --> and I gave below details
Host : IP of the Primary name node cluster
Port:10001
Server Type : Hive Server 2
Authentication Mechanism : User Name --> hadoop
While testing the connection, it throws the following error
Error:
Driver Version: V1.2.13.1018
Running connectivity tests...
Attempting connection
Failed to establish connection
SQLSTATE: HY000[Hortonworks][Hardy] (34) Error from Hive: connect() failed: errno = 10061.
TESTS COMPLETED WITH ERROR.
Could you please tell me if the port I use is correct ? If not, what port should I try ? The port 10000 doesn't work either.
I am using HDP 2.0 on Windows 2012 R2 Server (Single Node Cluster). I Installed Hive ODBC Driver from Microsoft site. I gave my Host Name and Port :10001 and user as hive. When I installed HDP 2.0 in Win 2012 Server R2, I gave the Hive User Name as hive. I am able to connect successfully.
The answer of your problem is that first of all: check on your virtual machine that the port "10000" is added because it's not added by default.
If the port is there, you might check the hive Server if it's running from your virtual machine
I hope it will help.
under the mechanism changed it to user name only.