Trouble Connecting to Database Using R - mysql

I am trying to connect to an amazonaws.com database using details provided to me. However when I run my code I get the error of
"Error: nanodbc/nanodbc.cpp:1021: 08001: [Microsoft][ODBC Driver 18 for SQL Server]TCP Provider: Timeout error [258]. [Microsoft][ODBC Driver 18 for SQL Server]Login timeout expired [Microsoft][ODBC Driver 18 for SQL Server]Unable to complete login process due to delay in prelogin response."
or
"[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified."
Below are the drivers currently installed on the machine:
[1] "SQL Server"
[2] "ODBC Driver 18 for SQL Server"
[3] "Microsoft Access Driver (*.mdb, *.accdb)"
[4] "Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)"
[5] "Microsoft Access dBASE Driver (*.dbf, *.ndx, *.mdx)"
[6] "Microsoft Access Text Driver (*.txt, *.csv)"
Below are two blocks of code I tried, neither of which successfully connect.
dbConnect(
drv = odbc::odbc(),
driver = "driver",
database = "database",
server = "server",
uid = "username",
pwd = "password")
and
dbConnect(RMySQL::MySQL(),
dbname = "databasename",
host = "amazonawsaddress",
port = port,
user = "username",
password = "password")
Thank you for any suggestions that helps me solve this issue.

Related

R ODBC: odbc::odbcListColumns doesn't list columns

I fully configured ODBC on Linux Ubuntu 20.04.
R can perfectly connect to the datasource but then it cannot even list columns:
con <- DBI::dbConnect(odbc::odbc(),
Driver = "MySQL ODBC 8.0 Driver",
Server = "127.0.0.1",
UID = "root",
PWD = "password",
Port = 3306,
database = "mydb",
)
odbc::odbcListColumns(con, table = "mytable")
Error:
Error in connection_sql_columns(connection#ptr, table_name = validateObjectName(table, :
null access
I'm using this documentation page: https://db.rstudio.com/r-packages/odbc/
Any ideas?

R - Error trying to connect to a MySQL server

I'm trying to connect to a MySQL database using this code:
con <- dbConnect(RMySQL::MySQL(),
dbname = "XX",
host = "YY",
port = ZZ,
user = "AA",
password = "BB"
)
And I'm getting this error:
Error in .local(drv, ...) :
Failed to connect to database: Error: Can't connect to MySQL server on 'YY' (0)
I've tried with this other code:
pool <- dbPool(drv = RMySQL::MySQL(),
dbname = "XX",
host = "YY",
username = "AA",
password = "BB",
port = ZZ
)
And get the same error:
Error in .local(drv, ...) :
Failed to connect to database: Error: Can't connect to MySQL server on 'YY' (0)
I can connect to this database using Workbench, so I guess it's a problem with R.
Any solution to this problem?
Edit: something I didn't say, the server is remote, so I had to use a SSH key to make the tunnel to the server to be able to access from Workbench. So maybe this should be considered to solve the issue.

Cannot connect to ODBC DSN

I want to connect to my ODBC DSN but I always get an error
$conn = new-object system.data.odbc.odbcconnection
$conn.ConnectionString = "Driver={MySQL ODBC 8.0 Unicode Driver};Server=k1000.ad.bac.work;Database=KACE;User=usr;Password=pwd;Option=3"
$conn.Open()
if($conn.Open() -eq $true){
Write-Host "Connection is open"
}
else{
Write-Host "Connection failed"
}
Name : KACE
DsnType : System
Platform : 32-bit
DriverName : MySQL ODBC 8.0 Unicode Driver
Error MSG:Exception calling "Open" with "0" argument(s): "ERROR [HY000] [MySQL][ODBC 8.0(w) Driver]Access denied for user 'usr'#'%' to database 'KACE'
My goal is to get the entire table of a DB in a csv file scripted.

SQL Server 2008 R2 connectionstring

global.asa
Application("Connection_ConnectionString") = "Provider=SQLOLEDB.1;Persist Security Info=False;Data Source=127.0.0.1;Initial Catalog=O2JAMTRADE;User ID=USERNAME;PWD=PWD"
Application("m_Connection_ConnectionString") = "Provider=SQLOLEDB.1;Persist Security Info=False;Data Source=127.0.0.1;Initial Catalog=O2JAMTRADE;User ID=USERNAME;PWD=PWD"
Application("c_Connection_ConnectionString") = "Provider=SQLOLEDB.1;Persist Security Info=False;Data Source=127.0.0.1;Initial Catalog=O2JAM;User ID=USERNAME;PWD=PWD"
Application("Connection_ConnectionTimeout") = 80
Application("Connection_CommandTimeout") = 80
This is my problem:
Microsoft OLE DB Provider for SQL Server error '80004005'
[DBNETLIB][ConnectionOpen (Connect()).]SQL Server does not exist or access denied.
/payment/payment_input_01.asp, line 40
And this is line 40:
Conn.Open(Application("Connection_ConnectionString"))
Please help.

Asterisk 1.8 cdr-adaptive mysql

i'm having a little problem. I'm using Debian and I got asterisk 1.8 and I want to use CDR along with mysql.
In Asterisk 1.8 you apparently gotta use cdr-adaptive module instead of the regular. That is just what I did. Now I have 1 error when I "module reload cdr_adaptive_odbc.so" and I can't solve it :
WARNING[23172]: cdr_adaptive_odbc.c:123 load_config: No such connection 'MySQL-asterisk' in the 'adaptive-connection' section of cdr_adaptive_odbc.conf. Check res_odbc.conf.
Now here are all the files related, I can't understand what is wrong :
/etc/odbc.ini :
[MySQL]
Description = MySQL ODBC MyODBC Driver
Driver = /usr/lib/libmyodbc3.so
FileUsage = 1
[Text]
Description = ODBC for Text Files
Driver = /usr/lib/libodbctxt.so
Setup = /usr/lib/libodbctxtS.so
FileUsage = 1
CPTimeout =
CPReuse =
[PostgreSQL]
Description = PostgreSQL driver for Linux & Win32
Driver = /usr/lib/libodbcpsql.so
Setup = /usr/lib/libodbcpsqlS.so
FileUsage = 1
[DB2]
Description = DB2 Driver
Driver = /opt/IBM/db2/V8.1/lib64/libdb2.so
FileUsage = 1
DontDLClose = 1
DMEnvAttr = SQL_ATTR_UNIXODBC_ENVATTR={DB2INSTANCE=db2inst1}
[MySQL-asterisk]
Description = MySQL asterisk database
Driver = MySQL
Socket = /var/run/mysqld/mysqld.sock
Server = localhost
User = root
Password = XXXXX
Database = ics
Option = 3
/etc/asterisk/cdr_adaptive_odbc.conf :
[adaptive-connection]
connection = MySQL-asterisk
table = cdr
alias start => calldate
/etc/asterisk/res_odbc.conf :
[Asterisk]
enabled => yes
dsn => MySQL-asterisk
username => root
password => XXX
;pooling => no
;limit => 0
pre-connect => yes
This is what I get when i check the cdd status :
Call Detail Record (CDR) settings
----------------------------------
Logging: Enabled
Mode: Simple
Log unanswered calls: No
* Registered Backends
-------------------
Adaptive ODBC
cdr-custom
ODBC
csv
radius
res_config_sqlite
And this is what I get when i check de odcb
ODBC DSN Settings
-----------------
Name: Asterisk
DSN: MySQL-asterisk
I can't figure out what's wrong. Anyone has an idea ?
I assume you've fixed this now. I ran into a similar issue and the problem stemmed from the documentation. It refers to connection= in cdr_adaptive_odbc.conf being the DSN name. It's the name you want and not the DSN. So in your case:
connection = Asterisk
then at the command line do a
CLI> module reload cdr_adaptive_odbc.so
and you should see a screenfull as Asterisk finds the tables and does any mappings you have specified.