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
Related
I have downloaded Microsoft SQL Server on my Mac with the Docker image as described here, and also I have downloaded the database AdventureWorks2019 as an example which I found it here.
So far so good. Everything works fine.
Now I want to import this database in my RStudio.
I followed the instructions which I found here.
So I opened RStudio and I typed the following:
con <- DBI::dbConnect(odbc::odbc(),
Driver = "SQL Server",
Server = "localhost",
Database = "AdventureWorks2019",
uid = "sa",
pwd = "<YourStrong#Passw0rd>",
port = 1433,
Trusted_Connection = "True")
I get an error
Error: nanodbc/nanodbc.cpp:1021: 00000: [unixODBC][Driver Manager]Can't open lib 'SQL Server' : file not found
Meanwhile the container in Docker is active and the localhost is active (green) in MS SQL.
I searched on the web for similar errors on Mac and I am more confused.
Any help? Someone?
This works for me:
con <- DBI::dbConnect(
odbc::odbc(),
Driver = "SQL Server",
Server = "server",
Database = "database",
UID = "uid",
PWD = "pwd"
)
I don't think you need Port and Trusted_Connection?
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")
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.
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
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")