I've followed the documentation on db.rstudio.com and other sites, and I'm not able to connect to my Postgres database from Rstudio. I'm on macos 10.14. Running:
con <- DBI::dbConnect(odbc::odbc(),
Driver = "PostgreSQL Driver",
Database = "mydatabase",
UID = "myuser",
PWD = "mypassword",
Host = "localhost",
Port = 5432)
Gives the error:
Error: nanodbc/nanodbc.cpp:983: 00000:
At first, I got an empty list when running odbcListDrivers(), however I was able to get it to show the postgres driver location/value by copying odbcinst.ini from the global /etc to my user (cp /etc/odbcinst.ini ~/.odbcinst.ini).
Similarly, odbcListDataSources() returned nothing until I did the same thing (cp /etc/odbc.ini ~/.odbc.ini)
The odbc.ini and odbcinst.ini are locked from editing via Finder, but can be edited via nano/terminal.
I also tried to solve the problem by installing the database drivers via Postgres' stack builder, but it didn't change anything.
Overall I'm suspecting that it's a permissions issue, but I'm not quite sure where to look next.
Thanks for your help!
The permission for the odbc.ini was:
-rw-rw-rw-# 1 root wheel 139B Mar 31 12:57 odbc.ini
Which I changed to:
-rwxr-xr-x# 1 myuser wheel 139B Mar 31 12:57 odbc.ini
But that didn't solve the problem, the error is the same.
The content of odbcinst.ini is:
[PostgreSQL Driver]
Driver = /usr/local/lib/psqlodbcw.so
The content of odbc.ini is:
[PostgreSQL]
Driver = PostgreSQL Driver
Database = mydatabase
Servername = localhost
UserName = myuser
Password = mypassword
Port = 5432
odbc::odbcListDrivers() gives:
name attribute
1 PostgreSQL Driver Driver
2 ODBC Drivers Amazon Redshift
3 Amazon Redshift Driver
value
1 /usr/local/lib/psqlodbcw.so
2 Installed
3 /opt/amazon/redshift/lib/universal/libamazonredshiftodbc.dylib
odbc::odbcListDataSources() gives:
name description
1 PostgreSQL PostgreSQL Driver
Related
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
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 have a FileMaker db running on FileMaker Server 14 on a Mac Mini and I'm trying to get at it with pyodbc. It's not going well.
First, what works:
telnet 192.169.19.3 2399
ssh Name#192.169.19.3
tsql -H FM-Server -p 2399 -U Name -P pwd
One weird thing about that last one is that it gives me a seconds counter:
1
2
not a prompt, although I can still type commands in. I'm not sure what that means and couldn't find any info about it.
Now, what doesn't work:
tsql -LH 192.169.19.3
tsql -LH FM-Server
isql FM-Server Name pwd
No listed info for the FileMaker Server, isql gives me [ISQL]ERROR: Could not SQLConnect which is just so helpful you know
One issue is that at this point I've sort of forgotten if I should be using FM ODBC or FreeTDS as my driver in pyodbc, luckily neither of them work:
>>> c = pyodbc.connect("DRIVER={FreeTDS};DSN=FM-Server;UID=Name;PWD=pwd")
pyodbc.Error: ('08001', '[08001] [unixODBC][FreeTDS][SQL Server]Unable to connect to data source (0) (SQLDriverConnect)')
>>> c = pyodbc.connect("DRIVER={FileMaker ODBC};DSN=FM-Server;UID=Name;PWD=pwd")
pyodbc.Error: ('08S01', '[08S01] [unixODBC][FileMaker][FileMaker ODBC] Failed to connect to listener (2) (65535) (SQLDriverConnect)')
Giving it just the DSN freezes the window. Here's my configs:
odbc.ini | /usr/local/Cellar/unixodbc/2.3.4/etc/odbc.ini
[FM-Server]
Driver = FreeTDS
Host = 192.169.19.3
ServerName = FM-Server
UID = Name
PWD = pwd
Port = 2399
odbcinst.ini | /usr/local/Cellar/unixodbc/2.3.4/etc/odbcinst.ini
[ODBC Drivers]
FileMaker ODBC = Installed
FreeTDS = Installed
[FileMaker ODBC]
Driver = /Library/ODBC/FileMaker ODBC.bundle/Contents/MacOS/fmodbc.so
Setup =
[FreeTDS]
Description = FreeTDS
Driver = /usr/local/Cellar/freetds/1.00.9/lib/libtdsodbc.0.so
Setup = /usr/local/Cellar/freetds/1.00.9/lib/libtdsodbc.0.so
UsageCount = 1
freetds.conf | /usr/local/Cellar/freetds/1.00.9/etc/freetds.conf
[FM-Server]
host = 192.169.19.3
port = 2399
tds version = 8.0
Any info is much appreciated and shout to the resources here, here, and elsewhere for helping me get even this far.
I was able to solve this with the following, slightly abbreviated
brew uninstall freeDTS
brew uninstall unixODBC
pip uninstall pyodbc
re-installed pyodbc with ActualTech's installer (not sure if necessary): http://www.actualtech.com/python-osx-odbc.php
switched my odbc.ini to read "Driver=FileMaker ODBC" instead of "Driver=freeTDS" but given the code I actually ran I'm not that that's necessary:
python
import pyodbc
c = pyodbc.connect("DRIVER={FileMaker ODBC};SERVER=192.169.19.3;PORT=2399;UID=Name;PWD=pwd")
and magically that worked. idk man
I have my odbc.ini and odbcinst.ini as follows
odbcinst.ini
[asterisk-connector]
Description = MySQL connection to 'asterisk' database
Driver = MySQL
Database = asterisk
Server = localhost
UID = asterisk
password = <mypassword>
Port = 3306
Socket = /var/run/mysqld/mysqld.sock
And the odbcinst.ini will look like this:
~ $ more /etc/odbcinst.ini
[MySQL]
Description = ODBC for MySQL
Driver = /usr/lib/x86_64-linux-gnu/odbc/libmyodbc.so
Setup = /usr/lib/x86_64-linux-gnu/odbc/libodbcmyS.so
FileUsage = 1
the res_odbc.conf file so it looks like the following:
[asterisk]
enabled => yes
dsn => asterisk-connector
UID => asterisk
password => <myPassword>
pooling => no
limit => 1
pre-connect => yes
And after running odbc show in asterisk CLI I see as follows.
ip*CLI> odbc show
ODBC DSN Settings
-----------------
Questions:
1) In the tutorial they see
*CLI> odbc show
ODBC DSN Settings
-----------------
Name: asterisk
DSN: asterisk-connector
Last connection attempt: 1969-12-31 19:00:00
Pooled: No
Connected: Yes
1) Why am I not seeing the Name and DSN when I run odbc show ?
2) Also I get this
[Jul 16 18:38:25] NOTICE[10970]: chan_sip.c:29427 sip_poke_noanswer: Peer 'nexmo' is now UNREACHABLE! Last qualify: 81
[Jul 16 18:38:36] WARNING[11288]: db.c:285 db_execute_sql: Error executing SQL: database is locked
Most likly you have error somewhere.
First can be recommended check files in odbcinst.ini are present and valid.
If they are, do following:
asterisk -rvvvvv
module unload res_config_odbc.so
module load res_config_odbc.so
You will see where is error in your config.