Connect to Firebird DB via ODBC - r

I am trying to connect to a firebird DB via ODBC. I have an working ODBC Windows Connection (ODBC Data Sources 32 Bit) and also an established connection via Tableau. I tried using dbConnect but was not able to set the right parameters I guess. I tried
library(odbc)
con <- dbConnect(odbc::odbc(),
drv = "Firebird/InterBase(r) driver",
database = "VARIO",
uid = "xxx",
pwd = "xxx",
host = "192.xxx.xxx.xx",
port = "xxxxx")
in e.g. Excel I can access the database by using the established windows connection. Anyways, sorry for my beginner formulation!
To add here, it seems I am running on 64 bit R Version
> Sys.info()[["machine"]]
[1] "x86-64"
After your comments I tried
con <- dbConnect(odbc::odbc(),
dsn = "VARIO",
database = "192.168.XX.X/56300:VARIO8",
uid = "XXX",
pwd = "XXX",
host = "192.168.XX.X",
port = "56300")
>Error: nanodbc/nanodbc.cpp:983: 01S00: [ODBC Firebird Driver]Unable to connect to data source: library 'C:\Users\XXX\Desktop\fbclient.dll' failed to load [ODBC Firebird Driver]Invalid connection string attribute [ODBC Firebird Driver]Invalid connection string attribute
fbclient.dll is there where its supposed to be
What is more I did not put an driver. Whenever I ad
drv = "Firebird/InterBase(r) driver"
I get: Error in (function (classes, fdef, mtable) :
unable to find an inherited method for function ‘dbConnect’ for signature ‘"character"’
Maybe this helps? This is from the Windows ODBC Data Sources and says 32/64 Bit. Don't know if this is imprtant
Any further Ideas?

Checking against the list of odbc-known DB drivers, Firebird doesn't seem to be a known driver.
library(odbc)
odbc::odbcListDrivers()
(src: https://rdrr.io/cran/odbc/man/odbcListDrivers.html)
I guess you would have to install that driver on your machine and then register the Data Source Name (DSN) to make it available to R.
Once that's done, please change the drv in your function call to dsn. drv refers to the odbc::odbc() argument which you've provided above, while dsn should then refer to the installed driver by its registered name (unless I'm mixing up things badly here. I've luckily never had to leave the warm comfort of RPostgreSQL...).
So it would look something like this:
library(odbc)
con <- dbConnect(drv = odbc::odbc(),
dsn = "Firebird", # this should be the DSN you have set
database = "VARIO",
uid = "xxx",
pwd = "xxx",
host = "192.xxx.xxx.xx",
port = "xxxxx")

Related

Connection R with odbc using ini -fle

I am trying to connect to a MySQL database from within R using odbc. If I write the connection information it works well, however, if I put the same information in a odbc.ini file, I get an error.
Here is the code that works
library(DBI)
con <- DBI::dbConnect(odbc::odbc(),
Driver = "MySQL ODBC 8.0 ANSI Driver",
Server = "localhost",
UID = "myname",
PWD = "mypassword",
Database = "vgr",
encoding = "latin1",
Port = 3306)
And here the code that doesn't work
con <- DBI::dbConnect(odbc::odbc(), 'MySQL')
The error is (it looks like dbConnect doesn't find the information):
Error: nanodbc/nanodbc.cpp:983: IM002: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
This is in my odbc.ini either in the working directory or where Windows saves it ODBC.ini file.
[MySQL]
Driver = MySQL ODBC 8.0 ANSI Driver
Server = localhost
UID = myname
PWD = mypassword
Database = vgr
encoding = latin1
Port = 3306
Any help would be appreciated.
Cheers
Renger

ODBC Connection to ORACLE in R

I am using both the DBI and ODBC package in "R" in order to make a connection to an ORACLE database.
Here is the connection code I am using:
library(DBI)
library(odbc)
con <- DBI::dbConnect(odbc::odbc(),
Driver = "ORACLE",
Host = "orasada.ca",
SVC = "STG",
UID = "username",
PWD = "password",
Port = 1521)
Everything looks fine to me, but I keep getting this error:
Error: nanodbc/nanodbc.cpp:983: IM002: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
Any ideas on what I can change to make a successful connection?
Thanks.

MongoDB Connection in Rstudio with odbc

I'm trying to connect to a mongoDB database using library(odbc) in R. First I installed the driver from here and then I have used the following method:
con <- dbConnect(odbc::odbc(),
Driver = "MongoDB ODBC 1.3.0 Unicode Driver",
Server = "xxxxx",
AuthMechanism = "SCRAM-SHA-1",
Port = 27017,
Database = "test",
UID = "utest",
PWD = "ptest"
)
However the following error will happen:
Error: nanodbc/nanodbc.cpp:983: 08S01: [MySQL][ODBC 1.3(w) Driver]Lost
connection to MySQL server at 'waiting for initial communication
packet', system error: 10060
I would appreciate any help.Thanks

Establish Microsoft SQL Server Connection with R/RStudio

I am trying to connect R with Microsoft SQL server. I have used Toad for SQL Server 6.8 so far for my queries. However, for some other analysis (which can be easily performed in R) I want to connect database with R.
I have tried R function "dbconnect" with providing server name and database name. See query below:
odbc_con <- dbConnect(odbc::odbc(),
Driver = "SQL Server",
Server = "xxxxx",
Database = "yyyyy",
Uid = 'US\dhrdesai',
Pwd = rstudioapi::askForPassword("Database password"),
Port = 1433)
However, I got following errors:
Error: nanodbc/nanodbc.cpp:950: IM002: [Microsoft][ODBC Driver
Manager] Data source name not found and no default driver specified
and
Error: unexpected ')' in " Port = 1433)"
Have anyone faced the same or know any other way to connect R with SQL server.
You need to use a double backslash \\ every time you see a \. I just made my connection work yesterday with the following code. Also pehaps you have not installed all the packages that is required.
library(DBI)
library(dbplyr)
library(odbc)
con <- dbConnect(odbc::odbc(),
Driver = "SQL Server",
Server = "path\\path", # remember \\ if your path has a \
Database = "the_database_name",
user = "your_user_name", # remember \\ if your username has a \
Trusted_Connection = "True")

Connect with rpostgresql

I have build up a postgresql 9.2 database. My table looks like that:
CREATE DATABASE "EURUSD_M1"
WITH OWNER = fadmin
ENCODING = 'UTF8'
TABLESPACE = pg_default
LC_COLLATE = 'German_Germany.1252'
LC_CTYPE = 'German_Germany.1252'
CONNECTION LIMIT = -1;
However when trying to connect thorugh the rpostgresql driver I get:
> drv <- dbDriver("PostgreSQL") ## loads the PostgreSQL driver
> con <- dbConnect(drv, port='5432', dbname='EURUSD_M1',
+ user='fadmin') ## Open a connection
Error in postgresqlNewConnection(drv, ...) :
RS-DBI driver: (could not connect fadmin#local on dbname "EURUSD_M1"
)
btw to specify host = 'localhost' does not change anything! Also fadmin is a superuser in my db!
Here are further connection information:
Any ideas what I am doing wrong?
I appreciate your answers!
RPostgreSQL, just like the psql command-line tool, connect via tcp/ip network interface even when you have the server on the same machine.
For this to work, you must enable network access; see the various PostreSQL HOWTOs and guides. You probably have to edit / alter a file call pg_hba.conf or similar.

Resources