RODBC odbcDriverConnect() Connection Error
Asked Answered
C

4

22

I'm trying to use

odbcDriverConnect('driver={SQL Server};server=servername\instancename,port;database=testing;username=abc;password=123456') 

to connect remote database server (sql server 2008). But I got

[RODBC] ERROR: state 08001, code 17, message [Microsoft][ODBC SQL Server Driver][DBNETLIB]SQL Server does not exist or access denied.

error. Any idea?

I can use

odbcDriverConnect('driver={SQL Server};server=localhost;database=testing;trusted_connection=true') 

to connect my local database server (sql server 2008).

Collado answered 14/3, 2013 at 21:59 Comment(0)
C
35

The correct syntax should be:

odbcDriverConnect('driver={SQL Server};server=servername\\instancename,port;database=testing;uid=abc;pwd=123456')

If you use Windows Authentication method:

odbcDriverConnect('driver={SQL Server};server=servername\\\\instancename,port;database=testing;trusted_connection=true')

Slash seems like an escape character, escaping slash works.

Collado answered 15/3, 2013 at 16:0 Comment(0)
A
11

For the Microsoft ODBC Driver 11 for SQL Server on Linux with RODBC version 1.3-7 in R version 3.0.1 none of the above answers worked. What did work however was the following:

dbconnection <- odbcDriverConnect("Driver=ODBC Driver 11 for SQL Server;
                Server=127.0.0.1; Database=MyDBName; 
                Uid=MyName; Pwd=XXXX")

(put in the relevant IP address, database name etc.).

In case of a trusted connection:

dbconnection <- odbcDriverConnect("Driver=ODBC Driver 11 for SQL Server;
                Server=127.0.0.1; Database=MyDBName; 
                Uid=MyName; Pwd=XXXX; trusted_connection=yes")

trusted_connection will only listen to "yes" or "no" and not to "true" and "false"

Alsacelorraine answered 1/9, 2013 at 18:21 Comment(0)
O
1

1.Connet to MySQL

a)if Mysql is installed in your system, if not install it.

b)download the RMySQL IN R

library(RMySQL)

drv = dbDriver("MySQL 5.0.1")

make sure MySQL version is correct.

con = dbConnect(drv,host="localhost",dbname="test",user="root",pass="root")

use local host or use the server i.e ip address

use the required database name, user name and password

album = dbGetQuery(con,statement="select * from table")

run required query

close(con)

2.Another way to connect database

a)first install any database like MySQL,Oracle,SQL Server

b)install the ODBC connector for database

library(Rodbc)

channel <- odbcConnect("test", uid="ripley", pwd="secret")

test is the connection name of odbc conector which user has to set manualy

user can find this in Administrator tool

res <- sqlFetch(ch, "table name")

A table can be retrieved as a data frame

res<-sqlQuery(channel, paste("select query"))

part of the with condition one table can be retrieved as a data frame

sqlSave(channel, dataframe)

to save a dataframe to the database(dont use "res<-" something like this)

like user can use

sqlCopy() sqlDrop()

sqlTables()

close(channel)

always close the connection

Overseas answered 17/3, 2013 at 14:58 Comment(0)
A
0

Looks like you are trying to connect to the SQL Server. This code snippet should work, it worked for me:

library("RODBC")

connection <- DBI::dbConnect(odbc::odbc(), Driver = "SQL Server", Server = "Your Server Name", Database = "Your Database Name", UID = "Your Database Name", UID = "Your Server Login", PWD = "Your Server Password", Port = 1433)

Reference: Connecting MS SQL Server via R

Azores answered 10/12, 2019 at 16:21 Comment(1)
Where's the explanation for putting a negative remark on that?Azores

© 2022 - 2024 — McMap. All rights reserved.